[racket] λ vs lambda

704 views
Skip to first unread message

Michael Rice

unread,
May 14, 2012, 11:09:15 AM5/14/12
to us...@racket-lang.org
The code below (kons) gets flagged in R5RS:  

define: not allowed in an expression context in: (define dispatch (λ (m) (cond ((= m 0) x) ((= m 1) y) (else (error "Argument not 0 or 1 -- KONS" m)))))

Works fine if I replace the lambda symbols with "lambda".

Cause?

Michael

============= 

From page 91 in SICP (slightly modified):

(define kons (λ (x y)
    (define dispatch (λ (m)
        (cond ((= m 0) x)
              ((= m 1) y)
              (else (error "Argument not 0 or 1 -- KONS" m)))))
    dispatch))

(define (kar z)
    (z 0))

(define (kdr z)
    (z 1))

Ray Racine

unread,
May 14, 2012, 11:23:58 AM5/14/12
to Michael Rice, us...@racket-lang.org
R5RS does not specify 'λ'.  It's just another character like 'A' or 'a'.  In Racket, the language, λ and lambda are equivalent.

____________________
 Racket Users list:
 http://lists.racket-lang.org/users


Grant Rettke

unread,
May 14, 2012, 11:25:42 AM5/14/12
to Ray Racine, us...@racket-lang.org
Can we hack DrRacket to display a lambda instead of the word lambda like pretty-mode in emacs?
--
http://www.wisdomandwonder.com/
ACM, AMA, COG, IEEE

Danny Yoo

unread,
May 14, 2012, 11:25:11 AM5/14/12
to Michael Rice, us...@racket-lang.org
On Mon, May 14, 2012 at 11:09 AM, Michael Rice <limi...@gmail.com> wrote:
> The code below (kons) gets flagged in R5RS:

Unfortunately, the error message is not reporting the leftmost error
in this situation. The real source of the problem is that the lambda
character λ is not in R5RS. The whole purpose of the r5rs language is
to be extremely conservative.

Jens Axel Søgaard

unread,
May 14, 2012, 1:19:44 PM5/14/12
to Michael Rice, us...@racket-lang.org
2012/5/14 Michael Rice <limi...@gmail.com>:

> The code below (kons) gets flagged in R5RS:
>
> define: not allowed in an expression context in: (define dispatch (λ (m)
> (cond ((= m 0) x) ((= m 1) y) (else (error "Argument not 0 or 1 -- KONS"
> m)))))
>
> Works fine if I replace the lambda symbols with "lambda".
>
> Cause?

Insert this macro definition at the top of your R5RS code.

(define-syntax λ
(syntax-rules ()
((_ . more) (lambda . more))))

--
Jens Axel Søgaard

Reply all
Reply to author
Forward
0 new messages