lambda(-macro) ideas

Started by jsmall, September 28, 2004, 06:48:52 AM

Previous topic - Next topic

jsmall

Suppose that lambda and lambda-macro were identical

except that the former had strict evaluation of actual

arguments and the latter lazy evaluation of actual

arguments.  Make this the default behavior (which it is

now).  But suppose newlisp had atomatized behavior like

this:





     (lambda (x ~y)  ....)    ;; y is lazy



     (lambda-macro (!x y) ...)   ;;  x is strict





Also if newlisp allowed something like the following





    (define (foo x y) ...)



    (~foo 1)





which had the effect of cloning foo on the fly

returning





    (lambda (y , x) (set 'x 1)  ... ;; old foo)





then this would allow transparent currying.  It seems

with the lambda lists that doing this sort of thing

of rotating argument would not be that difficult to

add to newlisp.



The default behavior of



    (define (bar) ...)



    (~bar)



would simply return bar.





A different approach to:



     (lambda (x ~y)  .... (eval y) ...)    ;; y is lazy



could be



     (lambda (x (f y))  .... (f x) ...)    ;; y is lambda argument



This would be interpreted as



     (lambda-macro (!x f-body)

        (set 'f (expand (lambda (y) f-body) 'f-body))

         ...)



We could then call it like this



     ((lambda (x (f y)) ... (f y) ...) 1 (println y))



In other words the actual argument passed would be

wrapped in a lambda expression having a y argument.

Instead of our expression being lazily evaluated it would

be delay evaluated, i.e. call by function instead of call by

name.