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

Re: [plt-scheme] eval question



  . . .
> One consideration is that Scheme has closures and macros.  These two
> tools will cover the majority of cases you'd use eval in a more
> rudimentary language.

I think there are at least two rather different situations that
might call for "eval".  Some more traditional languages (I don't want
to say "old-fashioned" :-) utterly divorce data and code, and have
nothing like closures, but implement an "eval" operation to bridge the
gap.  For example, SNOBOL, Perl, and Python all have "eval" operations
that interpret string arguments.
  Members of the the lisp family, on the other hand, have traditionally
unified code and data.  People have found lisp convenient for embedding
languages and building interpreters, and these applications sometimes
need "eval" to get through several levels of indirect reference, as well
as to evaluate a constructed lambda expression.  You may recall that
Common Lisp and some of its ancestors have both "set" and "setq", only
differing in that "set" evaluates its first argument (the target) while
"setq" does not.  The "set" form is useful for setting a variable bound
to another, which can occur when an interpreter binds embedded language
variables to interpreter variables.  When other operations beside
setting are desired, "eval" is useful.  For example, pass-by-reference
might be implemented this way, with dereferencing done by "eval"-ing the
formal.
  I suspect that "eval-twice" macro expansion was invented to regularize
and hide this sort of thing.  I've written a fair amount of lisp over
the
years; I can count the number of times I've really *needed* "set" on
both
hands, and the times I've needed "eval" on one.

FWIW,

 -- Bill Wood