lambda(-macro) ideas

For the Compleat Fan
Locked
jsmall
Posts: 26
Joined: Mon Sep 20, 2004 1:44 am

lambda(-macro) ideas

Post by 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:

<pre>
(lambda (x ~y) ....) ;; y is lazy

(lambda-macro (!x y) ...) ;; x is strict
</pre>

Also if newlisp allowed something like the following

<pre>
(define (foo x y) ...)

(~foo 1)
</pre>

which had the effect of cloning foo on the fly
returning

<pre>
(lambda (y , x) (set 'x 1) ... ;; old foo)
</pre>

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.

Locked