I'm twiddling with struct-plus-plus, adding declarative rules, and ~?
isn't doing what I expect. I expect that:

    (~? rule) ...

is equivalent to (~? rule (~@)) and means "If `rule` matched
something, insert it here.  Do this for each item that `rule` matched.
If `rule` did not match anything, put nothing here."  That's not what
I'm seeing, though.  The following is as stripped-down as I can get it
and still demonstrate the problem.

#lang racket
(require (for-syntax racket/syntax syntax/parse))

(define-syntax (struct++ stx)
  (syntax-parse stx
    [(_ name:id (field:id ...) (~optional (rule:expr ...)) opt ...)
     #'(begin (struct name (field ...) opt ...)
            (list (~? rule) ... ))]))

Given this declaration, it should be legal to omit the second set of
parentheses and their contents, but I'm getting compilation errors
when I do that.

; This works fine
(struct++ animal (species) ('testing 'testing) #:transparent)
(animal 'dog)

; As does this
(struct++ person (name age) ()  #:transparent)
(person 'bob 19)

; The lack of the second set of parens causes
; compilation to fail with the error:
;      ?: attribute contains non-list value
;      value: #f
(struct++ person (name age) #:transparent)
(person 'bob 19)

I can analyze it this far:  I'm using the (~? head-template) form
here.  `rule` is an identifier bound to a pattern variable, so `rule`
is a template.  All templates are head-templates, therefore `rule` is
a head template.  There were no rules for `rule` to match so `rule`
should be a missing pattern variable within the overall pattern, and
therefore the ~? form should emit nothing.

Clearly I'm not understanding something.  Can someone point me in the
right direction?

-- 
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