[plt-scheme] (let ((+ +) ...

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Apr 1 14:31:38 EDT 2008

Use modules.

On Apr 1, 2008, at 1:29 PM, Majorinc, Kazimir wrote:
> I do not like how redefinition of + changes the function "distance":
>
>
> > (define distance (lambda (x y)(sqrt (+ (* x x)(* y y)))))
> > (distance 4 3)
> 5
> > (define + -)
> > (distance 4 3)
> 2.6457513110645907
>
>
> It can be solved with:
>
>
> > (define distance (let ((+ +)(* *)(sqrt sqrt))
>                        (lambda(x y)(sqrt (+ (* x x)(* y y))))))
> > (distance 4 3)
> 5
> > (define + -)
> > (distance 4 3)
> 5
> >
>
> Is there any better way to accomplish the same?
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.