Another "syntax-case-y" version generates `define-values`:
(define-syntax-rule (aux clause ...)
(aux-helper () (clause ...)))
(define-syntax (aux-helper stx)
(syntax-case stx ()
[(_ ([id val] ...) ())
#'(define-values (id ...) (values val ...))]
[(_ (id+val ...) ([id val] more ..
> On May 24, 2019, at 7:35 AM, Stephen Chang wrote:
>
> If `define-values` is not strictly required, here's a more
> syntax-case-y recursive version:
>
> (define-syntax (aux stx)
> (syntax-case stx ()
>[(_) #'(begin)]
>[(_ (var val) . rst)
> (identifier? #'var)
> #'(begin
>
If `define-values` is not strictly required, here's a more
syntax-case-y recursive version:
(define-syntax (aux stx)
(syntax-case stx ()
[(_) #'(begin)]
[(_ (var val) . rst)
(identifier? #'var)
#'(begin
(define var val)
(aux . rst))]
[(_ var . rst)
(i
Let me propose the use of syntax-parse as an alternative here. I think it
clarifies the purpose of the maco. — Matthias
#lang racket
(require (for-syntax syntax/parse))
#; (aux a (b (* 2 pi)) c (d pi))
;; =>
#; (define-values (a b c d) (values #f 6.28318530717958 #f 3.141592653589793))
(beg
Does this work? It uses a helper function, `prune`, to parse the var-val
clauses.
#lang racket
(define-for-syntax (prune stx)
(syntax-case stx ()
[()
#'()]
[((var val) others ...)
(cons #'(var val)
(prune #'(others ...)))]
[(var others ...)
(cons #'(var #f
Thank you both -- Jon for the code and Alexis for the thorough description.
Alexis, this was exactly what I was looking for. I've been frustrated
with macros because I kept trying and failing to figure out a mental
model of what the heck was going on under the hood. I had some of the
basics, but
Jon is right. Here’s an explanation why.
Think of `...` as a postfix operator. It repeats what comes before it a certain
number of times. In order for `...` to know how many times to repeat the
previous head template, it looks inside the head template for any attributes
bound at the appropriate
On Fri, Feb 15, 2019 at 11:50 PM David Storrs
wrote:
>
> #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 ...)
8 matches
Mail list logo