Hi, For more explanation about my goal, here is "wrong" version :
#lang racket/gui (define frame (new frame% [label "test"])) (send frame show #t) (define-syntax (mk-widget stx) (syntax-case stx () [(_ (list (cons (datum->syntax k) v) ...)) #'(new button% [k v] ...)])) ; Work, but not my end goal (mk-widget (list (cons 'label "init") (cons 'parent frame) (cons 'stretchable-width #t))) ; My end goal ; (define d (list (cons 'label "init") (cons 'parent frame))) ; (mk-widget d) It works in the first case because I think that the variable is never created. My goal is the second case, where it is given by a variable. But I hope this can help a little. Is there a way to have a `list->syntax`? Thank you for reading, Denis Denis Michiels <dmichi...@mailoo.org> writes: > Hello, > > thank you for this start of response, but my goal is to be more general, > and not to make specific action (here, the label must be the first in > the list, ...). > > In fact, I want to "rewrite" the `new` function, but only with raw > data-type (like list and cons). Or at least, something that transform > raw data-type to the `new` function. > > And I hope it could be used for any class (at least for GUI class). Is > that possible or I'm trying to do something that is not the goal of > macro in Racket? > > kind regards, > Denis > > > Matthias Felleisen <matth...@felleisen.org> writes: > >>> On May 14, 2018, at 6:55 AM, Denis Michiels <dmichi...@mailoo.org> wrote: >>> >>> Hello, >>> >>> I'm trying to build a macro to be able to do : >>> >>> ``` >>> (define data (list (cons 'label "My button") >>> (cons 'stretchable-width #t))) >>> >>> (my-macro button% data) >>> ``` >>> >>> to be translated in : >>> >>> ``` >>> (new button% [label "My button"] [stretchable-width #t]) >>> ``` >>> >>> (I take gui example, and incomplete (like no frame) but it is to show my >>> goal) >>> >>> Unfortunately, I didn't manage well macro in Racket... >>> Can someone help me, or have a hint how to manage this macro? >>> >> >> #lang racket/gui >> >> (define data '((label "My button") (stretchable-width #t))) >> >> (define-syntax (mk-but stx) >> (syntax-case stx () >> [(_ data) >> #'(let () >> (match-define (cons label others) data) >> (define button (make-object button% (second label) frame)) >> (for ((o others)) >> (match-define (list m val) o) >> (dynamic-send button m val)))])) >> >> >> (define frame (new frame% [label "test"])) >> >> (mk-but data) >> >> (send frame show #t) -- 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.