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

data structures <--> functions



>Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742


In Lisp(s), one is able to build a list whose `car' is the atom `lambda',
and then apply this object as a function to arguments:

(setq add2 '(lambda (x) (+ 2 x)))
(lambda (x) (+ 2 x))

(add2 45)
47

Scheme seems to lack this property.  So does ML.  In short, the pun that
exists in classic lisps between data structures and functions seems to have
been abandoned.  Unless you write an interpreter subroutine, you cannot have
a program build a data structure and then use it as an executable function.

Is there some `sanctioned' way that a data structure that `looks' like a
lambda abstraction can be turned into a closure?  I tried opening a file for
writing, writing the object out, closing the file, opening it for reading,
and reading the object in using various read primitives, but that didn't
work.

The C Scheme interpreter I have (release 4.1.1) has an undocumented function
named `eval' (surprise!) that appears to take two arguments, an object
to be interpreted and an environment relative to which the interpretation
should take place.  By reading Scheme source code, functions to create
and manipulate environments can be found.

A more general question, for those well imbued in the Lisp culture:  how
much of a loss is it (or rather, `would it be' if there is in fact some
sanctioned, clean, efficient way to do the above) not to have a mechanism
for lisp programs to build their own functions?

- Greg Johnson
  johnson@mimsy.umd.edu