[racket] Evaluation problem

From: Mikko Tiihonen (mikko.tiihonen at tmtiihonen.fi)
Date: Sun Sep 30 17:43:31 EDT 2012

Hi!

I have been going through some lambda-calculus exercises with Racket. I have stumbled on a puzzling problem where beta-reduction by hand leads  to different result from that generated by Racket. 


(define select-first
  (lambda (first)
    (lambda (second)
      first)))

(define select-second
  (lambda (first)
    (lambda (second)
      second)))

(define make-pair
  (lambda (first)
    (lambda (second)
      (lambda (func)
        (func first) second))))

-----
> ((select-first 'a) 'b)
'a
> ((select-second 'a) 'b)
'b
> (((make-pair 'a) 'b) select-first)
'b
> (((make-pair 'a) 'b) select-second)
'b
-------

So, select-first returns the correct result when applied directly but returns the second argument when applied via make-pair. Also, I have checked that the implementation of make-pair gives the correct result if I do the beta-reduction by hand.

I suspect that I'm missing something obvious, but I really cannot find the reason why make-pair misbehaves - you gurus on this mailing-list probably can pinpoint the problem instantly :)

Best regards,

-Mikko Tiihonen

P.S.  Having used Racket for some months now, I find both Racket and the community around it really great!



Posted on the users mailing list.