Article View: misc.test
Article #257comp.lang.lisp
From: Bill Birch
Date: Tue, 03 Nov 1992 13:18
Date: Tue, 03 Nov 1992 13:18
62 lines
1868 bytes
1868 bytes
Adding closures to a shallow-binding interpreter.
I have a shallow-binding interpreter, which has no lexical closure.
My attempts to implement (function ) have been only partially succesful,
am I right in assuming that this is impossible?
So far my best attempt has been the following:
(defmacro my-function (fn)
`'(lambda (&rest f-args)
((lambdaq ,(bound-oblist)
(apply fn f-args))
,@(mapcar 'eval (bound-oblist)))))
I should explain that in in the interpreter:
lambdaq forms do not evaluate their arguments,
(bound-oblist) is a function that returns a list of all the symbols
with bound values.
symbols have only one value which can be a function
; Simple test case:
(setq free 67)
(setq my-test (my-function (lambda (a) (cons a free))))
(print (my-test 12))
(setq free 88)
(print (my-test 12))
; produces:
; (12 . 67)
; (12 . 67)
The simple cases work ok, however the following :
(setq free 67)
(setq my-test2 (my-function (lambda () (print free)(setq free 4))))
(my-test2)
(my-test2)
produces:
; 67
; 67
Where CLtL2 would want it to produce 67 4.
It is obvious why it cannot, but is there any way to do it?
Thanks in advance,
Bill
--
Bill Birch | B.Birch@uk03.bull.co.uk
Bull Info. Sys. Ltd. | Bull Tel: 773 4367
Maxted Road, | Bull Mail: HM14 UK03
Hemel Hempstead, | Tel: +44 442 884367
HERTS, HP2 7DZ, U.K. | Fax: +44 442 884570
Aviate, Navigate, Communicate...
Technical Details
Message-ID:
<1992Nov3.131832.2972@uk03.bull.co.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!pluto.uk03.bull.co.uk!bbirchShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!pluto.uk03.bull.co.uk!bbirch From: bbirch@hemel.bull.co.uk (Bill Birch) Newsgroups: misc.test Subject: comp.lang.lisp Message-ID: <1992Nov3.131832.2972@uk03.bull.co.uk> Date: 3 Nov 92 13:18:32 GMT Sender: @uk03.bull.co.uk Organization: Bull HN UK Lines: 62 Nntp-Posting-Host: brno