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

Re: [Sc-devel] environment-safe functions



On 11/24/07, James Harkins <jamshark70@xxxxxxxxx> wrote:
>
> Since the lists are back (yay!)...
>
> While updating ad hoc class syntax to remove the inconvenient "self"
> arguments, I had to come up with another mechanism to handle asynchronous
> functions (by which I mean any function that executes later than its
> appearance in the code, including callbacks for buffer reading, various
> responder functions [MIDI, OSC, HID, GUI], notification functions as in
> Updater or NotificationCenter, any scheduled function, etc.).
>
> If you're in one environment when you declare such a function and expect the
> function to act within the same environment,

You should not expect this. There are two kinds of scoping: lexical
scoping and dynamic scoping. If you want a function to execute with
the same variable bindings as where it was declared, then you want
lexical scope and should use lexical variables. If you want variables
that are bound based on the caller, then you should use dynamic
scoping (aka. currentEnvironment). But don't try to make one into the
other.

The correct solution is to make buf a local variable, not an
environment variable.


> If I had my druthers, we'd go through and make everything environment safe,

No, please no.

> Thoughts?

Use the correct scoping for the job.

-- 
--- james mccartney