[racket-dev] Proposal for a "no-argument"

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Jul 1 09:51:07 EDT 2012

Just now, Robby Findler wrote:
> If you're only going to use in keyword arguments (and optional
> arguments), you could make it an error to touch the value, unless it
> gets touched by a special predicate that checks for its existence.
> That is, in
> 
>  (define (f #:x [x]) ...)
> 
> (where I'm saying that leaving off the default value means it gets
> this new, special behavior),

(Just to clarify, I mentioned this option for completeness, but I
think that having a keyword will make things much simpler for macros
etc.)


> you'd bind, at compile time, 'x' to something that expands to a code
> that signals error and (is-default? x) would look at its argument
> and be able to actually implement the predicate.
> 
> In other words, I think you can devise a scheme where you don't
> actually have a value that leaks out at all.

Yeah, something like that could be done -- but there is a case where
you should be able to use `x' as a valid expression withouch checking,
when you wrap a function.  I should have added this to the examples to
show that case too.  Here's such an example for some `get-thing'
function that uses the `get-hash' from the previous message.  First,
with the current idiom:

  (define none (gensym)) ; need my own none value
  (define (get-thing name [default none])
    (if (eq? default none)
      (hash-ref things name)
      (hash-ref things name default)))

Second, with the #:nothing thing this is a little easier:

  (define nothing (gensym)) ; still need my own
  (define (get-thing name #:nothing [nothing nothing] [default nothing])
    (hash-ref things name default #:nothing nothing))

And using my proposal, it's much easier and there's no need for a new
"nothing" value since there's a single one:

  (define (get-thing name [default no-argument])
    (hash-ref things name default))

And that shows a use of `default' that would be valid even though it's
not tested.

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

Posted on the dev mailing list.