no continuations

Kevin S. Millikin kmillikin at atcorp.com
Tue Dec 30 17:03:38 EST 2003


On Tuesday, December 30, 2003 3:10 PM, Ben Rudiak-Gould 
[SMTP:benrg at dark.darkweb.com] wrote:
> Interesting.
>
> This still violates referential transparency, though. (c 'get) 
returns
> a value or errors out depending on whether (c 'set) has been called 
yet.

Oh, sure.  I didn't mean to quibble with the idea that continuations 
are computational effects.  Just wanted to point out that (I think) you 
can't macro express mutation with call/cc, unless you've already got 
mutation anyway.

> And take a look at this!
>
>   > (define c (make-cell))
>   > (define d c)
>   > ((d 'set) 9)
>   > (d 'get)
>
>   Error in car: #<procedure> is not a pair.
>   Type (debug) to enter the debugger.
>
> Something very nasty is going on here. I'm not sure exactly what it
> is, but I think at least one of the define statements is getting 
executed
> at least twice.

Yup.  If you do that, you can use d as your setter and c as your 
getter:

> (define c (make-cell))
> (define d c)
> ((d 'set) 9)
> (c 'get)
9
> ((d 'set) 17)
> (c 'get)
17

Does this help?:

> (define c
    (let ((cell (make-cell)))
      (display "Hi, Ben.")
      (newline)
      cell))
Hi, Ben.
> (define d c)
> ((d 'set) 9)
Hi, Ben.



More information about the Haskell mailing list