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

Re: [Sc-devel] environment-safe functions

On Nov 25, 2007, at 7:00 PM, James McCartney wrote:

On 11/24/07, James Harkins <jamshark70@xxxxxxxxx> wrote:
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

Well, I don't "expect" it in the sense that I understand why the behavior is the way it is, and I agree that the behavior of the language is correct as it is. And (even though it might have sounded like I was), I wasn't seriously suggesting that we should change all of those places to take environments into account.

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

From a CS theoretical perspective, yes, I am trying to simulate lexical scoping using dynamically-scoped environments (although in other places in my lib, I take advantage of dynamic scoping too). The thing is, the results are great, and I'll take my results over theoretical "correctness" any day.


: H. James Harkins

: jamshark70@xxxxxxxxxxxxxxxxx

: http://www.dewdrop-world.net


"Come said the Muse,

Sing me a song no poet has yet chanted,

Sing me the universal."  -- Whitman