[racket] syntax, differently

From: Marco Morazan (morazanm at gmail.com)
Date: Mon Aug 2 08:50:03 EDT 2010

On Sun, Aug 1, 2010 at 11:31 PM, Todd O'Bryan <toddobryan at gmail.com> wrote:
>> Like this:
>>
>> (define distance
>>  (case-lambda
>>   ((p q) (distance (posn-x p) (posn-x q) (posn-y p) (posn-y q)))
>>   ((x0 y0 x1 y1) (sqrt (+ (sqr (- x0 y0)) (sqr (- x1 y1)))))))
>>
> Right. But we don't let students do that! We don't even let them use
> ". rest" arguments for gosh sake! :-)
>

Right? What is "natural" about that? In my lonely corner of the woods
students would see nothing natural about the above. Well, not at the
beginning that is.

> But do we really want to have to introduce another function just to
> make the naming prettier? Alternatively, do we really want to have to
> introduce another piece of syntax just to make the naming prettier?
> Both approaches have negatives.

(define (distance p1 p2)
 ((lambda (x1 y1 x2 y2) (sqrt (+ (sqr (- x1 x2)) (sqr (- y1 y2)))))
(posn-x p1) (posn-y p1) (posn-x p2) (posn-y p2)))

"Introducing another function" *is* precisely what you are doing when
you use let. The added syntax "let" is just sugar coating for this
common practice.

-- 

Cheers,

Marco


Posted on the users mailing list.