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

RE: What's so cool about Scheme?



At 04:40 PM 2003.06.03 -0400, Anton van Straaten wrote:
>I agree that eval gives you crude HO "functions" - although they're not
>first-class functions in the sense that they aren't indistinguishable from
>functions implemented directly in the language.  However, the only way that
>I see this leading to "higher-order functions as a natural side-effect of
>code=data" is that if people start using eval in the way you suggest, they'd
>very soon be clamoring for a better feature, which proper HO functions could
>provide.

	Yes, perhaps this is exactly it.  You can trivially implement a form of higher-order functions with just code=data, but it will not be satisfactory; so as a language designer you'd better provide proper HOF's or all programs will be littered with this hack!

>To take Scheme's eval as a fairly typical example, there's no interaction
>between eval'd code and the lexical environment in which it is evaluated -
>the only interaction is with the dynamic, global environment.  This is not
>affected by the funarg problem.

	But this precludes lexically binding with variables in the definition environment, a natural thing to want to do.  This is I think a good reason why closures are necessary.

>In a language with non-global variables with dynamic scope, it's easy enough
>for an eval feature to allow evaluated code to bind to those dynamic
>variables.  When evaluating a piece of code, that binding can be made to
>work perfectly well.

	It's easy to bind to the *current* dynamic environment, but what about the dynamic environment at the point of definition?  Since the function argument might be evaluated any number of levels deep, the only real way I can see to do it is to capture the dynamic environment at the point of definition, a separate good reason to have closures.

	In summary having *just* code=data without closures, like the original LISP, causes all kinds of problems.  I think it does lead to users clamoring for something better.  There's no question about whether users will [ab]use eval, it's just too darn useful -- for poor-man's HOF's, for starters -- if there are no closures.