development version newLISP 8.8.6

Started by Lutz, May 01, 2006, 09:32:40 AM

Previous topic - Next topic

Lutz

• optional break condition in 'for, 'dolist' and 'dotimes'

• new 'letex' combines let and macro expansion

• bug fixes and doc additions/changes



files and change notes: http://newlisp.org/downloads/development/">http://newlisp.org/downloads/development/



Lutz

rickyboy

#1
I was looking at the manual for the 'letex' documentation.  It says:



"The last example shows how 'letex' can be combined with 'define-macro' to do variable expansion of macro variables into an expression to be evaluated:
(define-macro (dolist-while)
   (letex (var ((args) 0 0)
           lst ((args) 0 1)
           cnd ((args) 0 2)
           body ((args) -1))
       (catch (dolist (var lst)
           (if (set 'res cnd) body (throw res) )))))

> (dolist-while (x '(a b c d e f) (!= x 'd)) (println x))
a
b
c
nil

'dolist-while' loops through a list while the condition is true."



But, it will not work for a 'body' with more than one form:
> (dolist-while (x '(a b c d e f) (!= x 'd)) (print "x=") (println x))
a
b
c
nil

This one seems to work for multi-form 'body's.
(define-macro (dolist-while)
  (letex (var ((args) 0 0)
          lst ((args) 0 1)
          cnd ((args) 0 2)
          body (cons 'begin (1 (args))))
    (let (res)
      (catch (dolist (var lst)
               (if (set 'res cnd) body (throw res)))))))

> (dolist-while (x '(a b c d e f) (!= x 'd)) (print "x=") (println x))
x=a
x=b
x=c
nil


Thank you, Lutz, for providing this functionality.  --Ricky
(λx. x x) (λx. x x)

Lutz

#2
Thanks Rick for catching this, it will be corrected in the manual.



Lutz



ps: BTW 'letex' will do expansion on multiple expression bodies

newdep

#3
Yesssssss ..Thanks Lutz!!

you added some very nice extras in the last 2 releases!! great..
-- (define? (Cornflakes))

Lutz

#4
... and more to come, try newLISP's new syntax highlighting service here:



http://newlisp.org/code/highlight.html">http://newlisp.org/code/highlight.html



you can try it with Pjot's url: http://www.turtle.dds.nl/newlisp/speaker.lsp">http://www.turtle.dds.nl/newlisp/speaker.lsp



Lutz



ps: read more about it here: http://newlisp.org/index.cgi?page=News">http://newlisp.org/index.cgi?page=News