[racket] On (void) and interactions
I'm playing with encapsulated state in Advanced Student Language, and have noticed that sometimes I see "(void)" explicitly as a result in the interactions pane, and other times I see nothing at all.
Specifically, I was playing with two different ways to implement a posn with its own "swap" and "format" methods. One way, storing the methods as fields of a struct, I get the following behavior:
> (define here (build-with-swapper-and-formatter 3 4))
> (define there (build-with-swapper-and-formatter 5 -2))
> (my-posn-x here)
3
> (my-posn-y there)
-2
> ((my-posn-formatter here))
"(3, 4)"
> ((my-posn-swapper here))
> ((my-posn-formatter here))
"(4, 3)"
Note the lack of any visible result after the call to (my-posn-swapper here).
The other approach, wrapping everything up in a function that dispatches on its argument, gives me the following behavior:
> (define here (make-my-posn 3 4))
> (define there (make-my-posn 5 -2))
> (here 'x)
3
> (there 'y)
-2
> (here 'format)
"(3, 4)"
> (here 'swap)
(void)
> (here 'format)
"(4, 3)"
Note that this time the "swap" produced an explicit "(void)".
When does "(void)" print out, and when does it not? Why?
Stephen Bloch
sbloch at adelphi.edu