[plt-scheme] Okay, you've got me thinking (was: Quicksort in Scheme)

From: Felix Klock's PLT scheme proxy (pltscheme at pnkfx.org)
Date: Wed Jan 4 16:34:30 EST 2006

Greg-

On Jan 4, 2006, at 4:25 PM, Greg Woodhouse wrote:

> I suppose continuations provide a "way out" (albeit a heavy handed  
> one)
> for destructive operations like set!
>
>> (define strange
>   (lambda (a b)
>     (+ a
>        (call/cc
>         (lambda (k)
>           (set! a 0)
>           (k b))))))
>> (strange 4 5)
> 9
I think you're misinterpreting what you're seeing here.   What you  
did above is no different from

(define strange
   (lambda (a b)
     (+ a (begin (set! a 0) b))))

There's no "undoing" of the set! going on here.  You're just  
observing the order of evaluation; if you switched the arguments to  
+, you'd get a different answer.

-Felix








Posted on the users mailing list.