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?
Afficher les réponses par date
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@cs.nyu.eduwrote:
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?