[racket] Bouncing default value

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Feb 12 15:23:51 EST 2012

9 hours ago, Laurent wrote:
> Thank you all for your good and helpful answers.  Based on them,
> here is my current solution (without keywords), using macros to ease
> the function definition:
> #lang racket
> (define default (gensym))
> (define (default? x) (equal? x default))

(Using `eq?' here is a common idiom.)

In any case, the real point here is not the macro -- it's the
existence of a special `none' value that marks an unsupplied value.
It's potentially a convenient thing to have (which I wish for every
time I do that `gensym' dance), but it gets tricky with the fact that
you might want to actually use that value -- same as the undefined
value (which you get from (letrec ([x x]) x)) which could be used for
the same purpose.

(This comes up in other places like struct initialization with
optional fields -- in swindle I used the undefined value for that.
This is done in a similar way to what TR does: a field can have a
guard, but the undefined value is allowed as an exception because of
this kind of use.)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.