lazy-let & loop

Sam Steingold <[email protected]>
Newsgroups gmane.lisp.clisp.devel
Message-ID <[email protected]>
Hi Bruno, Jörg,

The following is an elaboration on
https://sourceforge.net/p/clisp/bugs/667/#2b06

The problem with loop is that under certain circumstances we separate
initializing and binding of a variable.

I wonder if something like "lazy-binding" could help: bind the variable
but not initialize its value. until it is explicitly set, accessing it
reaches up in the environment. This would require something like
`lazy-let` with the following test case:

--8<---------------cut here---------------start------------->8---
(let ((a 1))
  (lazy-let (a b)
    (print a) ; prints 1
    (print b) ; error - unbound variable
    (setq a 10) ; inner binding of a is activated
    (print a) ; prints 10
    (setq b 22)) ; binding of b is activated
  (print b) ; error - unbound variable
  (print a)) ; prints 1
--8<---------------cut here---------------end--------------->8---

while it is easy to avoid `lazy-let` above by putting `let` after the
second `print`, it is not so easy with `loop` because we need the
binding to exist around the main `tagbody` but to do initialization in
the preamble inside `tagbody`.

Loop expansion then will loop like this:

--8<---------------cut here---------------start------------->8---
(lazy-let (all the loop local variables thay are now bound by let)
  (tagbody 
     preamble - set all the loop local variables thay are now bound by let
     ...
     )) ; close tagbody and lazy-let
--8<---------------cut here---------------end--------------->8---

BTW, we can merge `lazy-let` and `tagbody` into a single form `taglet`:

--8<---------------cut here---------------start------------->8---
(taglet (variables to lazily bind)
  forms...
  tags...)
--8<---------------cut here---------------end--------------->8---

Alternatively, `lazy-let` can be implemented as something like

--8<---------------cut here---------------start------------->8---
(let ((a (if (boundp 'a) a (sys::%unbound))))
  ...)
--8<---------------cut here---------------end--------------->8---


wdyt? thanks.

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1504
http://steingoldpsychology.com http://www.childpsy.net http://mideasttruth.com
http://honestreporting.com http://memri.org http://iris.org.il
Rottweiler puppy for sale, eats everything, loves children.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.