What does * do in func.(*(x)) ? Where is it in the help browser?

I have a function

k=SynthDef( \t,{ | i | }).add;
b=[[ k , "ab", 1,2,3]];
x={ |i| i.postln};
x.(*a.slice(nil,0).clump(3)); // Error's out because clump is called on k

I expected in doing the slice, it would have returned an array and not a bare object. Is it supposed to work this way?

It turns each element in the array into subsequent arguments in a function call.

f.(*[1,2,3]) == f.(1,2,3)

Out of curiosity why did you write it if you don’t know what it does?

1 Like

From a code example, it looked like it was deconstructing the array, which was something I needed. In any case searching through the help browser for * yielded not so great results, plus I was expecting an array back from a slice, since it has always yielded arrays.

Ah! I see, thought it might have been made by an AI or something.

Also a isn’t defined in the code you have posted.

Typo there, should’ve been b.

Where is it in the help browser?

http://doc.sccode.org/Overviews/SymbolicNotations.html#Where%20f%20is%20a%20function

For good or ill, help search is geared toward method calls. * in this context isn’t a method call, so it’s not really searchable. I’m not sure what to do about that; I’d just observe that this exact same question comes up repeatedly on the forum.

However the * is irrelevant to the error here. The * always applies to the result of the entire expression:

x.( *( a.slice(nil,0).clump(3) ) )  // always

x.( *(a.slice(nil,0)).clump(3) )  // impossible

The “impossible” expression is literally impossible. The first one works because you have an expression that should produce an array, and its members get distributed across function/method arguments. The second reads like “1/ slice; 2/ distribute this result across arguments; 3/ clump that” but because the values would have been distributed, there is no “that” object to clump. So it’s meaningless.

Therefore in a * call, any errors related to the expression have to be resolved within the expression. So the issue is that slice isn’t returning what you expected (and AFAICS slice is undocumented, so the only way to know is to read the method source). This error is occurring even before * is doing anything.

But here, is the * useful at all? The function has one argument, and you’re splitting the array across arguments… so the call will only print the first array element, which can be written more simply as a.slice(nil,0).clump(3).at(0) (and run faster too).

hjh

1 Like

For good or ill, help search is geared toward method calls. * in this context isn’t a method call, so it’s not really searchable. I’m not sure what to do about that;

Online search engines actually are really useful when an official documentation search engine falls short. For instance, if you had the great ability to predict the exact description from the documentation you could type this into google

“evaluate the function with the arguments in an array” site:doc.sccode.org

And it will give you the correct page as well as a preview of the content where the search results are (though it won’t jump there when you click on the page). But this is only helpful if what you’re trying to figure out has intuitive keywords associated with it.

For example, in python this syntax is called argument unpacking. Granted, not everyone will know what that means, but it would definitely help for people that have seen it in similar languages if there was some mention of “unpacking” in the description.

If there’s some tutorial page that goes over using this syntax, you could also potentially include the word “asterisk” or “star” while describing the syntax because searching “*” isn’t very helpful for a number of reasons.

Another thing is to put it in more places in the documentation. For example, the Symbolic Notations page you linked is great, but I noticed there was a See Also: Syntax Shortcuts - I think it would probably be appropriate there as well!

1 Like

My promptieest prompt for the search engine is “what does the * do in front of an array?” And the similarly veined "What does the * do? and “Is the * a dereferencing operation in supercollider?”.

“in front of an array” is probably a great key search phrase for the documentation. e.g.

putting an asterisk (*) in front of an array argument will unpack the values of the array as arguments to the function