IMHO, one big advantage of using a closure over a list literal
is that you can close variables. I use this type of syntax
extensively:
(define (bind-it foo)
(canvas 'bind item event
(lambda (|W|) ( ... uses foo somewhere ... )))
(canvas 'bind item anotherevent
(lambda (|W|) ( ... uses foo somewhere ... )))
)
where you can refer to the local binding `foo' inside the bound
script. If you use a literal list, there's no easy way to do it.
> (define (script path str) (format #t (~a ~a~%") path str))
> (canvas 'bind item event '(script %|W| "hello"))
This can be written as
(canvas 'bind item event
(lambda (|W|) (script |W| "hello")))
BTW, I agree that it is certainly useful if you can write down
and read back a closure (body and environment) in a portable way.
--
Shiro Kawai
Programmer, or an inline hockey lover http://www.lava.net/~shiro
# The most important things are the hardest things to say --- Stephen King
Received on Thu May 11 2000 - 22:29:24 CEST