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

Re: [sc-users] Pseudo-method question



Hei Kenneth,

There is a difference with calling functions using subscript notation and methodname directly:
If you call the function using subscript, the arguments in the function are the same as in the caller:

m = ();
m[\dlt] = {arg ...args; "Args: %".format(args).postln;};
m[\dlt].value([1,2,3]);
// function


//When using the key as method name in the caller the first argument is the Event (or any subclass of IdentityDictionary) itself
n = ();
n.dlt = {arg ...args; "Args: %".format(args).postln;};
n.dlt([1,2,3]);

//This probably makes it even more clear:
n = (aNumber: 44);
n.dlt = {arg self...args; "Self: % Args: %".format(self, args).postln;};
n.dlt([1,2,3]);

This is related to the 'know' attribute for IdentityDictionary (and its subclasses) so you can read about in the helpfiles by searching after 'know'. There is one caveat related to using this prototype notation. you can't override already existing method names:

n = (aNumber: 44, size: {|self| "size my style: %".format(self).postln;});
n.size; //not size my style, but prints 2

But if you are careful with naming your methods it will be fine for a lot of things.

+Eirik


//
Eirik Arthur Blekesaune // Artist in Verdensteatret // +47 415 00 966
//

On Mon, Dec 26, 2016 at 8:56 PM, kflak <kennethflak@xxxxxxxxx> wrote:
Hi list,

Why does this work:

x = {arg data = "" data.postln};
x.value([1,2,3]);

and this not:

m = ();
m.dlt = {arg data = ""> m.dlt.value([1,2,3]);

?

K



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Pseudo-method-question-tp7629746.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.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/