[racket] eginner's question on elementary textual replacement...

From: Stephen Bloch (bloch at adelphi.edu)
Date: Fri Mar 9 07:42:15 EST 2012

On Mar 9, 2012, at 6:25 AM, Rüdiger Asche wrote:

> (define (vendingmachine currentstate)
>  (let ((newstate
>     (case currentstate
>         [(VENDINGMACHINE_IDLE)
>              (if (CoinInserted)
>                  VENDINGMACHINE_INSERTED_COIN
>                  VENDINGMACHINE_IDLE
>              )
>         ]
>         [(VENDINGMACHINE_INSERTED_COIN)
>              ...
> ...
> 
> where every of the VENDINGMACHINE_xxx identifiers is very simply a readable symbolic identifier for a disjoint constant. I have a hard time believing that in reasonably complex fsms, it shouldn't impose a severe performance penalty to look up a constant every time it is used?

Why not just use symbols for these, without worrying about what they "stand for"?  If you've implemented a Scheme system, you know about interned symbols: the symbol-table lookup should happen at compile-time (right?), so you're left with a constant-time pointer comparison at run-time.

Disclaimer: I've implemented only "toy"-scale Schemes myself.


Stephen Bloch
sbloch at adelphi.edu



Posted on the users mailing list.