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

From: Majorinc, Kazimir (kazimir at chem.pmf.hr)
Date: Tue Apr 1 13:29:05 EDT 2008

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?


Posted on the users mailing list.