answer 1) You are missing a dot in (~@ propthing), ie this will work:
(~@ . propthing)
minor question) is there a reason you are using with-syntax with syntax-parse?
answer 2) You may want to try "attribute". It's somewhat like
"syntax", except it returns false when there are unbound patvars, eg:
#lang racket
(require (for-syntax racket racket/syntax syntax/parse))
(define-syntax (foo stx)
(syntax-parse stx
[(foo name (~optional flag))
#:with propthing (if (attribute flag)
#'(#:property prop:foo (delay "stuff"))
#'())
#`(begin
(define-values (prop:foo foo? foo-ref)
(make-struct-type-property 'foo 'can-impersonate))
(struct name (id) (~@ . propthing) #:transparent)
(name 'bob))]))
(foo person)
(foo thing #f)
answer 3) A more "rackety" way would be if you included a part of the
output as the optional input. (this would invert your default case
though). This is the more natural use case for the ~? and ~@ patterns
because you no longer need the extra "if":
#lang racket
(require (for-syntax racket racket/syntax syntax/parse))
(define-syntax (foo stx)
(syntax-parse stx
[(foo name (~optional prop-val))
#`(begin
(define-values (prop:foo foo? foo-ref)
(make-struct-type-property 'foo 'can-impersonate))
(struct name (id) (~? (~@ #:property prop:foo (delay
prop-val))) #:transparent)
(name 'bob))]))
(foo person)
(foo thing "stuff")
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CAE8gKofM%3Dep0B%2BY0YXOq5uqooh-jDTBr7mZ9yDK%2BFrVVVbEHjA%40mail.gmail.com.
> For more options, visit
https://groups.google.com/d/optout.