I still don't understand why you need to define a macro for that. We write macros to manipulate _code_ by transforming a syntax object into another syntax object. Extracting a value from a hash table or generating a text from hash tables has nothing to do with syntax objects. And it can be done with basic programming.
Can you tell what you are trying to do with more details, perhaps? On Mon, Jul 6, 2020 at 4:23 AM Oualmakran Yassine <yassine...@gmail.com> wrote: > In fact, I would like to have a macro that will generate some text from a > list of hash tables for scribble. So this macro is just a first step to try > to achieve that (it's also the first time I try a non toy program in any > Lisp). > > Le lundi 6 juillet 2020 20:04:27 UTC+9, Sorawee Porncharoenwase a écrit : >> >> What's wrong with `match`? It seems to be what you want. Macro is not >> going to help you here. >> >> >> >> On Mon, Jul 6, 2020 at 3:47 AM Oualmakran Yassine <yassi...@gmail.com> >> wrote: >> >>> Hello, >>> >>> I have some difficulties when trying to create a macro doing some >>> pattern matching on a hash-table and was hoping finding some help. >>> The macro is taking a hash-table as parameter and I would like to >>> extract the value for the key 'name. >>> I did several trials of my macro with what should be, for my >>> understanding, the same hash-table but got always a different result. >>> Suprisingly, when I'm trying the same partern matching in a simple >>> "match" at runtime, I always get the answer expected. >>> >>> >>> Here is my code: >>> >>> (define-syntax (m stx) >>> (syntax-case stx () >>> [(_ (hash-table 'name n m ...)) >>> #'(symbol->string n)] >>> [(_ (hash-table x0 x1 ...)) >>> #'"..."] >>> [(_ (hash-table ('name n) (k v) ...)) >>> #'"FOO"] >>> [(_ (hash-table (k v) ...)) >>> #'"BAM"] >>> [(_ (hash-table (k0 v0) (k1 v1) ...)) >>> #'"BAZ"] >>> [(_ (hash-table x ...)) >>> #'"COMMON"] >>> [x #'"WHY"])) >>> >>> (define (define-person . fields) >>> (for/hash ([k '(name e-mail nickname)] >>> [field fields]) >>> (values k field))) >>> >>> (define person (define-person 'my-name 'my-email 'my-nickname)) >>> >>> ; gives why (why nothing before matches ?) >>> (m person) >>> >>> ; my-email >>> (m (define-person 'my-name 'my-email 'my-nickname)) >>> >>> ; gives my-name >>> (m (hash >>> 'name 'my-name >>> 'e-mail 'my-email >>> 'nickname 'my-nickname)) >>> >>> ; gives my-nickname >>> (m (hash >>> 'nickname 'my-nickname >>> 'name 'my-name >>> 'e-mail 'my-email)) >>> >>> >>> -- >>> 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...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/racket-users/82364adf-fe5d-4c6f-bf33-51852c423371o%40googlegroups.com >>> <https://groups.google.com/d/msgid/racket-users/82364adf-fe5d-4c6f-bf33-51852c423371o%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/946b66b0-71b0-44e4-abef-2b577d564dc7o%40googlegroups.com > <https://groups.google.com/d/msgid/racket-users/946b66b0-71b0-44e4-abef-2b577d564dc7o%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CADcuegtcsBtaUVOcPoPEQkTcdvDbXQEeA_F%2BYE%2Bh8hAbArB6rw%40mail.gmail.com.