Discussion on possible lambda syntax: Good or Evil?

Discussion of Common Lisp
Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

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

Post by Jasper » Sun Oct 12, 2008 10:29 pm

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.
Last edited by Jasper on Mon Oct 13, 2008 9:12 am, edited 1 time in total.

Paul Donnelly
Posts: 148
Joined: Wed Jul 30, 2008 11:26 pm

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

Post by Paul Donnelly » Sun Oct 12, 2008 10:50 pm

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.

Pauli

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

Post by Pauli » Thu Oct 23, 2008 11:55 pm

You might want to familiarize yourself with http://en.wikipedia.org/wiki/De_Bruijn_index .

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

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

Post by Jasper » Sun Feb 15, 2009 7:35 pm

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.

skypher
Posts: 34
Joined: Thu Jul 03, 2008 6:12 am

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

Post by skypher » Mon Feb 16, 2009 1:04 am


marcoxa
Posts: 85
Joined: Thu Aug 14, 2008 6:31 pm

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

Post by marcoxa » Tue Feb 17, 2009 5:05 am

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
Marco Antoniotti

Harleqin
Posts: 71
Joined: Wed Dec 17, 2008 5:18 am
Location: Bonn, Germany

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

Post by Harleqin » Tue Feb 17, 2009 5:06 pm

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

eric-and-jane-smith
Posts: 2
Joined: Fri Feb 20, 2009 5:29 am

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

Post by eric-and-jane-smith » Sat Feb 21, 2009 1:36 am

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))))

Post Reply