[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] spreading an array across multiple function arguments



hi,
* is like the opposite of ...
na.sendMsg(obj, method, *args);

_f

> 10 dec. 2019 kl. 18:35 skrev info@xxxxxxxxxxxxxxxx:
> 
> Dear all, 
> 
> I'm trying to write a helper function that wraps OSC message sends with variable arguments. The variable input arguments is no problem, using the `... args` syntax.
> 
> Now I'm wondering how to distribute the values of the args array across the input arguments of a function that also has variable arguments (NetAddr's sendMsg method).
> 
> This must be possible in SC lang, but I'm stumped on what to search for... I feel like I've even written functions that do this in the past...
> 
> right now my extremely ugly solution is to use a switch statement up to some number of reasonable arguments.
> 
> ```
> 
>   *send {|obj, method ... args|
>     var na = this.netAddr;
>     switch(args.size,
>       0, { na.sendMsg(obj, method) },
>       1, { na.sendMsg(obj, method, args[0]) },
>       2, { na.sendMsg(obj, method, args[0], args[1]) },
>       3, { na.sendMsg(obj, method, args[0], args[1], args[2]) },
>       4, { na.sendMsg(obj, method, args[0], args[1], args[2], args[3]) },
>       5, { na.sendMsg(obj, method, args[0], args[1], args[2], args[3], args[4]) },
>       6, { na.sendMsg(obj, method, args[0], args[1], args[2], args[3], args[4], args[5]) },
>       7, { na.sendMsg(obj, method, args[0], args[1], args[2], args[3], args[4], args[5], args[6]) },
>     );
>   }
> 
> ```
> -- 
> JReus
> 
> 
> jonathanreus.com
> sensorycartographies.info
> anatomiesofintelligence.github.io
> 
> 
> Recent:
> 
> Interview with PERFORM-TECH, by Fionn
>  Han
> 
> Interview with Asko-Schönberg Ensemble
> Interview with Leuphana University, Teaching Prize for Cross-Disciplinary Education Across Arts, Science and Humanities


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/