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 <[email protected] > <javascript:>> 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 [email protected] <javascript:>. >> 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/946b66b0-71b0-44e4-abef-2b577d564dc7o%40googlegroups.com.

