Re: [racket-users] macro-generate attribute access?

2015-08-22 Thread Alexander D. Knauth
Does this get you what you want?
#lang racket
(require (for-syntax syntax/parse racket/syntax))

(define-syntax (define-stuff stx)
 (syntax-parse stx
   [(_ attr-name macro-name)
#:with c.attr-name (format-id #'c "~a.~a" #'c #'attr-name)
#'(begin
(begin-for-syntax
  (define-syntax-class C
(pattern any #:attr attr-name #'any)))
(define-syntax macro-name
  (syntax-parser
[(_ (~var c C))
 #'c.attr-name])))]))
(define-stuff an-attr a-macro)
(a-macro 1)


On Aug 21, 2015, at 12:57 PM, Stephen Chang  wrote:

> Is there a way to access an attribute, other than with the "." syntax?
> 
> For example, the following example does not work:
> 
> #lang racket
> (require (for-syntax syntax/parse))
> 
> (define-syntax (define-stuff stx)
>  (syntax-parse stx
>[(_ attr-name macro-name)
> #'(begin
> (begin-for-syntax
>   (define-syntax-class C
> (pattern any #:attr attr-name #'any)))
> (define-syntax macro-name
>   (syntax-parser
> [(_ (~var c C))
>  #'c.attr-name])))]))
> (define-stuff an-attr a-macro)
> (a-macro 1)
> 
> I've also tried various format-id's which I also can't get to work. Is
> there an alternate way, in the spirit of ~var vs ":", to get an
> attribute's value?
> 
> -- 
> 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.

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


[racket-users] macro-generate attribute access?

2015-08-21 Thread Stephen Chang
Is there a way to access an attribute, other than with the "." syntax?

For example, the following example does not work:

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

(define-syntax (define-stuff stx)
  (syntax-parse stx
[(_ attr-name macro-name)
 #'(begin
 (begin-for-syntax
   (define-syntax-class C
 (pattern any #:attr attr-name #'any)))
 (define-syntax macro-name
   (syntax-parser
 [(_ (~var c C))
  #'c.attr-name])))]))
(define-stuff an-attr a-macro)
(a-macro 1)

I've also tried various format-id's which I also can't get to work. Is
there an alternate way, in the spirit of ~var vs ":", to get an
attribute's value?

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