Re: [racket-users] Wrong result from a define-syntax with pattern maching on a hash table

2020-07-06 Thread Sorawee Porncharoenwase
#lang scribble/manual

@(require (only-in racket ~a))

@(define persons (list (hash
'name 'name1
'e-mail 'email1
'nickname 'nickname1)
   (hash
'name 'name2
'e-mail 'email2
'nickname 'nickname2)
   (hash
'name 'name3
'e-mail 'email3
'nickname 'nickname3)))

@(define (generate-section person)
   (list @section{Here's a section for @(~a (hash-ref person 'name))}
 @subsection{My information}
 @itemlist[
   @item{Email: @(~a (hash-ref person 'e-mail))}
   @item{Nickname: @(~a (hash-ref person 'nickname))}
 ]))

@(map generate-section persons)


generates this document:

[image: Screen Shot 2020-07-06 at 05.09.08.png]

On Mon, Jul 6, 2020 at 5:01 AM Oualmakran Yassine 
wrote:

>  Sure.
>
> I would like to create a document with a repetitive structure in scribble.
>
> Let say I have something like this:
> @section{First section}
> Some text ...
> @subsection{First subsection}
> @itemlist...
>
> @section{Second section}
> Some text ...
> @subsection{Second subsection}
> @itemlist...
>
> etc.
>
> I would like to know how is it possible to have this without writing
> multiple section, subsection, etc. every time (the purpose is more to
> understand how the language works than anything else).
>
> --
> 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/4c4194c0-ff05-4dee-9b44-53b9e2e00e0eo%40googlegroups.com
> 
> .
>

-- 
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/CADcuegsbW5F_2vrAWp2GMr%3Dd55kxHiKYE7ADdoKPckWfZ5B1Jg%40mail.gmail.com.


Re: [racket-users] Wrong result from a define-syntax with pattern maching on a hash table

2020-07-06 Thread Oualmakran Yassine
 Sure.

I would like to create a document with a repetitive structure in scribble.

Let say I have something like this:
@section{First section}
Some text ...
@subsection{First subsection}
@itemlist...

@section{Second section}
Some text ...
@subsection{Second subsection}
@itemlist...

etc.

I would like to know how is it possible to have this without writing 
multiple section, subsection, etc. every time (the purpose is more to 
understand how the language works than anything else). 

-- 
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/4c4194c0-ff05-4dee-9b44-53b9e2e00e0eo%40googlegroups.com.


Re: [racket-users] Wrong result from a define-syntax with pattern maching on a hash table

2020-07-06 Thread Sorawee Porncharoenwase
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 
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 
>> 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
>>> 
>>> .
>>>
>> --
> 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
> 
> .
>

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


Re: [racket-users] Wrong result from a define-syntax with pattern maching on a hash table

2020-07-06 Thread Oualmakran Yassine
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  > 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
>>  
>> 
>> .
>>
>

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


Re: [racket-users] Wrong result from a define-syntax with pattern maching on a hash table

2020-07-06 Thread Sorawee Porncharoenwase
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 
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-users+unsubscr...@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
> 
> .
>

-- 
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/CADcuegt1-aR-Bi-Reb-gGouj8sCo%2B7Zun60R3HgUUh0YxKx%2BmA%40mail.gmail.com.


[racket-users] Wrong result from a define-syntax with pattern maching on a hash table

2020-07-06 Thread Oualmakran Yassine
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-users+unsubscr...@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.