Super!!! ... thanks a ton Jens.
Now I'll go over the docs to understand why it works :)
Regards,
Kashyap

On Thu, Sep 22, 2016 at 8:52 AM, Jens Axel Søgaard <[email protected]>
wrote:

> Here is a bit more.
>
> #lang racket
>
> (require (for-syntax syntax/parse racket/syntax)
>          syntax/parse/define)
>
> (define-simple-macro (define-primitive-application-syntax
> (primitive-name:id arg:id ...))
>   (define-simple-macro (primitive-name arg-expr:expr (... ...))
>     (list 'primitive-name arg-expr (... ...))))
>
> (define-syntax (define-primitive stx)
>   (syntax-parse stx
>     [(_ (primitive-name:id arg:id ...) body ...+)
>      #:with table-name (format-id #'primitive-name "~a-property-table"
> #'primitive-name)
>      #'(begin
>         (define table-name (hash 'is-prime #t
>                                  'arg-count (length '(arg ...))
>                                  'emitter (lambda (arg ...) body ...)))
>         (define-primitive-application-syntax (primitive-name arg ...)))]))
>
> (define-primitive (plus x y) (+ x y))
> plus-property-table
>
>
> 2016-09-22 17:36 GMT+02:00 C K Kashyap <[email protected]>:
>
>> Thanks Jens ...
>> I think I'm almost there....I get this "primitive-name: pattern variable
>> cannot be used outside of a template in: primitive-name" at the very end
>> now....
>>
>> (require syntax/parse/define)
>>
>> (define-simple-macro (define-primitive-application-syntax
>> (primitive-name:id arg:id ...))
>>   (define-simple-macro (primitive-name arg-expr:expr (... ...))
>>     (list 'primitive-name arg-expr (... ...))))
>>
>> (define-syntax (define-primitive stx)
>>   (syntax-parse stx
>>     [(_ (primitive-name:id arg:id ...) body ...+)
>>      #:with table-name
>>             (format-id #'primitive-name "~a-property-table"
>> #'primitive-name)
>>      #'(begin
>>         (define table-name (hash 'is-prime #t
>>         'arg-count (length '(arg ...))
>>         'emitter (lambda (arg ...) body ...))))
>>
>>         (define-primitive-application-syntax (primitive-name arg
>> ...))])) ; ERROR here
>>
>>
>>
>> On Thu, Sep 22, 2016 at 8:30 AM, Jens Axel Søgaard <[email protected]
>> > wrote:
>>
>>> Remove the ().
>>>
>>> The construct syntax-case needs the () which in general can be a list of
>>> identifiers,
>>> but most often an empty list, (), is used. Any identifiers in the list
>>> are treated
>>> by syntax-case as a literal.
>>>
>>> The construct syntax-parse does not use a list of identifiers. It uses
>>> an alternative
>>> way of specifying literal identifiers.
>>>
>>> /Jens Axel
>>>
>>>
>>> 2016-09-22 17:27 GMT+02:00 C K Kashyap <[email protected]>:
>>>
>>>> Thanks Andrew ... I got past that error. I now get an error below -
>>>> " syntax-parse: expected clause in: ()"
>>>>
>>>> (define-syntax (define-primitive stx)
>>>>   (syntax-parse stx () ; ERROR
>>>>     [(_ (primitive-name:id arg:id ...) body ...+)
>>>>      #:with table-name
>>>>             (format-id #'primitive-name "~a-property-table"
>>>> #'primitive-name)
>>>>      #'(begin
>>>>         (define table-name (hash 'is-prime #t
>>>>         'arg-count (length '(arg ...))
>>>>         'emitter (lambda (arg ...) body ...))))
>>>>
>>>>         (define-primitive-application-syntax (primitive-name arg
>>>> ...))]))
>>>>
>>>> On Thu, Sep 22, 2016 at 8:21 AM, Andrew Kent <[email protected]> wrote:
>>>>
>>>>> The '...' that is causing the error is a '...' at the level of the
>>>>> _initial/outer_ macro (define-primitive-application-syntax), and so
>>>>> your final use of '...' is trying to splice a parameter of the _initial
>>>>> macro_ (define-primitive-application-syntax), but you are actually
>>>>> trying to output a _literal_ '...' in the syntax you are generating 
>>>>> because
>>>>> you want it to be a part of the macro you are generating/defining via
>>>>> define-primitive-application-syntax (i.e. primitive-name).
>>>>>
>>>>> TL;DR you want this instead I believe:
>>>>>
>>>>> …
>>>>> (define-simple-macro (define-primitive-application-syntax
>>>>> (primitive-name:id arg:id ...))
>>>>>   (define-simple-macro (primitive-name arg-expr:expr (... ...))
>>>>>     (list 'primitive-name arg-expr (... ...))))
>>>>>
>>>>> --
>>>>> 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].
>>>>> 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 [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> --
>>> Jens Axel Søgaard
>>>
>>> --
>>> 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].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>
>
> --
> --
> Jens Axel Søgaard
>
>

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to