Discussion on possible lambda syntax: Good or Evil?
Re: Discussion on possible lambda syntax: Good or Evil?
I don't like any of them very well, but the one with the dollar signs the best. See no particular reason to use $1 ,etc and not $any-symbol. I admit have not giving it that much thought. About needing to move dollar signs, if it is longer code, the (lambda(blabla) body) would be small relative to the body, so just writing the lambdas would be better anyway. Edit: needs to tell which argument it is, silly me.
All these examples use manipulation of the strings the symbols contain. I really dislike that, for one. Also, people might use it when they should be using flet or small functions(with function output). Making syntax like this could distract from making good code.
All these examples use manipulation of the strings the symbols contain. I really dislike that, for one. Also, people might use it when they should be using flet or small functions(with function output). Making syntax like this could distract from making good code.
Last edited by Jasper on Mon Oct 13, 2008 9:12 am, edited 1 time in total.
-
- Posts: 148
- Joined: Wed Jul 30, 2008 11:26 pm
Re: Discussion on possible lambda syntax: Good or Evil?
I think the idea is to avoid declaring parameters, using numbers to refer to first arg, second arg, etc.Jasper wrote:I don't like any of them very well, but the one with the dollar signs the best. See no particular reason to use $1 ,etc and not $any-symbol.
Re: Discussion on possible lambda syntax: Good or Evil?
You might want to familiarize yourself with http://en.wikipedia.org/wiki/De_Bruijn_index .
Re: Discussion on possible lambda syntax: Good or Evil?
I have the feeling that you might be refering to De Bruijn notation instead of the indexes, but i might be wrong. Those wikipedia pages are rather dense, i don't know lambda calculus, i guess.
Re: Discussion on possible lambda syntax: Good or Evil?
Evil. IMHO. No questions about it.
The only reason to have something like this is to make CL more Perl-ish (thus raising the self-esteem of Lisp programmers, which may be a worthy goal after all)
Cheers
--
Marco
The only reason to have something like this is to make CL more Perl-ish (thus raising the self-esteem of Lisp programmers, which may be a worthy goal after all)
![Mr. Green :mrgreen:](./images/smilies/icon_mrgreen.gif)
Cheers
--
Marco
Marco Antoniotti
Re: Discussion on possible lambda syntax: Good or Evil?
At least it should be done with a dispatch character. Otherwise, it just looks like a mistake in the code.
"Just throw more hardware at it" is the root of all evil.
Svante
Svante
-
- Posts: 2
- Joined: Fri Feb 20, 2009 5:29 am
Re: Discussion on possible lambda syntax: Good or Evil?
Code: Select all
; cf = Compose function with optional currying.
; Example usage:
; (mapcar (cf (* 2) (+ 10 20) -) '(1 2 3))
; ==> (-32 -34 -36)
; Each argument to cf gets converted to a function,
; and the functions are applied in left to right
; order. E.g. (cf f1 f2 f3) is equivalent to
; (lambda (x) (f3 (f2 (f1 x))))
; Arguments accepted by cf:
; * #'name and 'name have their usual meanings.
; I.e. #'name names a function in lexical scope
; but 'name is only global.
; * name (unquoted) is #'name with #' elided. Note
; this contradicts the normal Lisp convention.
; * ''form has the same meaning form unquoted would
; have in the normal Lisp convention. E.g. to
; get the function from a variable as in
; (funcall var) use ''var instead of just var.
; * (/x a b c) is shorthand for (lambda (x) a b c)
; But there is no /y or anything, just /x.
; * (func 1 2 3) is to curry. I.e. it gets
; converted to (lambda (x) (func x 1 2 3))
; * Special case: If one of the curry args is a $
; then the non-curried arg takes the place of the
; $ instead of being leftmost.
; (func 1 2 $) = (lambda (x) (func 1 2 x))
; E.g. (cf (+ 1) (/ 1 $)) = 1/(x+1)
(defmacro cf (&rest xs)
(loop with argname = (gensym)
as x in (cons nil xs)
as curryargs = nil
as func = (if (atom x)
`#',x
(case (car x)
(quote (if (and (consp (cadr x))
(eq (caadr x) 'quote))
(cadadr x)
x))
(function x)
(/x `(lambda (x) ,@(cdr x)))
(t (setq curryargs (cdr x))
`#',(car x))))
as args = (if (member '$ curryargs)
(loop as x in curryargs collect
(if (eq x '$) argname x))
(nconc (list code) curryargs))
as code = argname then `(funcall ,func ,@args)
finally (return `(lambda (,argname) ,code))))