Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!godot.cc.duq.edu!newsgate.duke.edu!news.mathworks.com!uunet!in2.uu.net!world!wware
From: wware@world.std.com (Will Ware)
Subject: Re: Q re lambda
Message-ID: <DunCy6.Mw4@world.std.com>
Organization: The World Public Access UNIX, Brookline, MA
X-Newsreader: TIN [version 1.2 PL2]
References: <Dun16t.6r6@world.std.com>
Date: Tue, 16 Jul 1996 17:37:18 GMT
Lines: 39

In response to my question, Brian Harvey <bh@CS.Berkeley.EDU> wrote:
: Most versions of Scheme will let you say

: (eval '(define f (lambda ...)))

: although it's not in the standard.  There's no official way to
: construct code on the fly -- the compiler writers are too worried
: about efficiency, I believe.

This worked (at least with MzScheme), thanks very much.

Welcome to MzScheme version 42, Copyright (c) 1995-96 Matthew Flatt
> (set! f (cons 'lambda (cons () '((printf "3") (printf "4")))))
> (f)
apply: (lambda () (printf "3") (printf "4")) (type <pair>) not a procedure (no arguments)
;;
;; That didn't work, but this did:
;; 
> (eval '(define f (lambda () (begin (printf "3") (printf "4")))))
> f
#<procedure>
> (f)
34> 

;;
;; This also worked:
;;
~> mzscheme
Welcome to MzScheme version 42, Copyright (c) 1995-96 Matthew Flatt
> (define fdef '(define (f) (printf "3") (printf "4") (printf "~%")))
> (eval fdef)
> (f)
34
> 

-- 
-------------------------------------------------------------
Will Ware <wware@world.std.com> web <http://world.std.com/~wware/>
PGP fingerprint   45A8 722C D149 10CC   F0CF 48FB 93BF 7289
