Re: binding script syntax

From: Shiro Kawai <shiro_at_lava.net>
Date: Thu, 11 May 2000 10:29:06 -1000

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

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST