[gambit-list] keyword argument: unspecified, or specified to #f?

Matthew Koichi Grimes mkg at cs.nyu.edu
Sun Jun 19 20:35:03 EDT 2011


Whoops, I should've read the docs more closely. You can specify your own
default values for unspecified keywords:

> (define (my-func #!key (bool-arg 'unspecified)) (if (eq? bool-arg
'unspecified) "bool-arg unspecified" bool-arg))
> (my-func)
"bool-arg unspecified"
> (my-func bool-arg: #t)
#t
> (my-func bool-arg: #f)
#f

Sorry for the spam,
-- Matt

On Sun, Jun 19, 2011 at 6:28 PM, Matthew Koichi Grimes <mkg at cs.nyu.edu>wrote:

> When a keyword argument is left unspecified, it is initialized to #f. This
> can get weird for optional boolean arguments. For example:
>
> Example:
>
> > (define (my-func #!key bool-arg) (if bool-arg bool-arg "bool-arg
> unspecified"))
> > (my-func bool-arg: #t)
> #t
> > (my-func)
> "bool-arg unset"
> > (my-func bool-arg: #f)
> "bool-arg unset"
>
> Is there any way to distinguish between keyword arguments that were never
> set, and keyword arguments that were set to #f?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20110619/112102ed/attachment.htm>


More information about the Gambit-list mailing list