[mercury-users] Impurity and foreign language calls

Peter Hawkins hawkinsp at cs.stanford.edu
Thu Mar 16 11:20:30 AEDT 2006

doug.auclair at logicaltypes.com wrote:

>Dear Ian, thanks for your reply.  You wrote:
>Thanks for that.  I also saw this approach under the
>debugging thread as well.  I have a slight problem with
>this, and that is material use:  the 'camera' is the 
>entire world for this app, and there's no stdin and stdout
>that reads/writes ASCII characters.  So, should I then
>modify module io so that stdin is the battery power
>reading and stdout is the command interface?
Only if that would be a convenient thing to do for other reasons. Think 
of the IO state not just for "input and output", rather as encoding the 
state of the world, that is, everything that isn't part of the program. 
If you inspect the state of the world (eg. read the battery state of the 
camera) you need to have a copy of it! If you write to the state of the 
world, you destroy the old state and make a new one.

>Or should I just suck it up and grimace everytime I
>add this unused state variable (IO1 = IO0 all over the
>place, ugh!)?
No need for the IO1 = IO0 stuff. Use state variable syntax (reference 
manual section 2.10) and that will happen automatically.
Incidentally there's no runtime cost at all for passing IO state around, 
since the compiler optimizes away all references to the IO state --- 
it's just a linguistic construct for talking about "the world" and 
doesn't actually exist at runtime.

>Or should I choose a reasonable, aesthetic alternative
>-- if battery power is the state variable (altered at
>each C call that obtains the current charge), then every
>non-unique call will produce the same result, right?
>Making the call-out pure, correct?
Effectively what you're doing here is creating another IO state that 
describes things related to the camera. Why have another one? It's no 
more convenient, and it's not at all obvious how the two IO states 
should interact. Just use the global IO state and be happy.

mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list