Page 2 of 2

Re: Discussion on possible lambda syntax: Good or Evil?

PostPosted: Sun Oct 12, 2008 10:29 pm
by Jasper
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.

Re: Discussion on possible lambda syntax: Good or Evil?

PostPosted: Sun Oct 12, 2008 10:50 pm
by Paul Donnelly
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.

I think the idea is to avoid declaring parameters, using numbers to refer to first arg, second arg, etc.

Re: Discussion on possible lambda syntax: Good or Evil?

PostPosted: Thu Oct 23, 2008 11:55 pm
by Pauli
You might want to familiarize yourself with http://en.wikipedia.org/wiki/De_Bruijn_index .

Re: Discussion on possible lambda syntax: Good or Evil?

PostPosted: Sun Feb 15, 2009 7:35 pm
by Jasper
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?

PostPosted: Mon Feb 16, 2009 1:04 am
by skypher

Re: Discussion on possible lambda syntax: Good or Evil?

PostPosted: Tue Feb 17, 2009 5:05 am
by marcoxa
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) :mrgreen:

Cheers
--
Marco

Re: Discussion on possible lambda syntax: Good or Evil?

PostPosted: Tue Feb 17, 2009 5:06 pm
by Harleqin
At least it should be done with a dispatch character. Otherwise, it just looks like a mistake in the code.

Re: Discussion on possible lambda syntax: Good or Evil?

PostPosted: Sat Feb 21, 2009 1:36 am
by eric-and-jane-smith
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))))