I would like to write a macro that accepts an optional keyword
argument.  If the argument is missing, or if it is present and has a
true value, then some code will be generated.  Otherwise, nothing is
done.  This was my best attempt:

#lang racket
(require (for-syntax syntax/parse))
(define-syntax (foo stx)
  (syntax-parse stx
    [(foo name val (~optional (~seq #:make-double? make-double?:boolean)))
     (with-syntax ([func (if (syntax->datum #'(~? make-double? #'#t))
                             #'(define (doubleup) (* 2 val))
                             #'(begin))])
       #'func)]))

(foo x 6 #:make-double? #t)
doubleup


No joy.  doubleup is never defined, no matter what happens with the
keyword.  I'm not sure what I'm doing wrong -- any advice?

More generally, this feels like something for which there should be a
simpler solution.  I think that ~? isn't quite what I'm looking for,
since the thing that I'm testing for defined/truth isn't going to be
used in the code that will actually be generated. What should I be
using?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to