compact lambda expressions

Ralf Juengling <[email protected]> Sun, 9 Nov 2008 17:40:08 -0800 (PST)
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
On Mon, 20 Oct 2008, Ralf Juengling wrote:

> I would like to simulate partial evaluation and do something
> slightly more general with @ as the macro character. It would
> take the S-expression following @ and build a lambda expression
> from it. The symbols $1, $2, etc. and .. are treated special
> [..]

This is now in svn. I used the macro-character #\, since '\'
looks almost like a lambda. The downside is that #\ is used in
common lisp to refer to characters (#\A, #\SPACE, etc.). But we
don't have a character datatype, so this is not a problem I guess.


? ^Acompact lambda

------------------------------------------------------------------------
Compact Lambda Expressions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Anonymous functions (lambda expressions) are often used in combination
with higher-order functions like mapcar or filter .

  (filter (lambda (f) (str-endswith f "jpg")) (ls "data/images"))

Lush allows to define lambda expression more compactly using the
macro-character '#\' . The macro character must be followed by a lisp
form, the body of the lambda expression. Positional arguments to the
lambda have the canonical names $1 , $2 , and so on. The
highest-numbered symbol of the form $i determines the number of
arguments of the lambda expression (i less than 10).

  (filter #\(str-endswith $1 "jpg") (ls "data/images"))

  (#\(- $5 $3) 10 11 12 13 14)

The positional arguments may be followed by an arbitrary number of
optional arguments. The optional arguments are referred to with the
ellipsis, .. .

  (#\(+ $3 ..) 1 2 3 4 5)  ; ignore first two

  (#\(/ (+ ..) (length (list ..))) 1 2 3 4 3)  ; average

= ()




-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/