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

Re: [sc-users] let type statements in SC?



Yes SC does have closures like lisp.

(
var makeAFunc, f1, f2;

makeAFunc = { arg harry;
	// return a function which takes bill as an argument
	// and refers to harry in enclosing context
	{ arg bill; bill * harry }
};

f1 = makeAFunc.value(30); // create a function with harry bound to 30
f2 = makeAFunc.value(40); // create a function with harry bound to 40

f1.value(1.1).postln; // 33
f2.value(1.2).postln; // 48

)

On Saturday, December 7, 2002, at 08:24  PM, Michael Theodore wrote:

Hello,
I do the following in lisp all the time:

(let ((joe 2)(momma 1))
(defun blah (armyboots)
    (* joe momma armyboots)))

Looking over some work I've started, I'm realizing that being able to do so in SC would help me reuse a fair amount of code. Is there a suave way to
bind variables and functions within protected environments inside of
programs? While this doesn't work, I'm looking to do something like:

(
var f1, f2;
    (
        var harry = 30
        f1 = { arg bill;
        bill * harry};
    )
    (
        var harry = 40
        f2 = { arg bill;
        bill * harry};
    )
)
,
where each harry is bound to a separate environment enclosing each of the
functions.
If this isn't possible, is there a way to have function variables
have initial values without having to call the function with a special
argument depending upon whether one is initializing or not?
If none of this is clear, I apologize and blame the sake......
thanks,
Michael

_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users


--
--- james mccartney   james@xxxxxxxxxxxxxx   <http://www.audiosynth.com>
SuperCollider - a real time synthesis programming language for the PowerMac.
<ftp://www.audiosynth.com/pub/updates/SC2.2.16.sea.hqx>