Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!mimsy!johnson
From: johnson@mimsy.UUCP (Greg Johnson)
Newsgroups: comp.lang.scheme
Subject: data structures <--> functions
Message-ID: <9597@mimsy.UUCP>
Date: Wed, 2-Dec-87 14:14:11 EST
Article-I.D.: mimsy.9597
Posted: Wed Dec  2 14:14:11 1987
Date-Received: Sun, 6-Dec-87 02:14:45 EST
Reply-To: johnson@mimsy.UUCP (Greg Johnson)
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 34

Summary:

Expires:

References:

Sender:

Followup-To:

Distribution:

Keywords:



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