Re: [racket-users] Macros that conditionally generate code

2019-03-07 Thread Greg Hendershott
This reminds me of a similar thread on Slack yesterday. When a macro `define`s something, it's usually better for everyone if the identifier is supplied to the macro. It's nicer for you as the macro writer because you don't need to think so hard about scope and hygiene. And it's nicer for the user

Re: [racket-users] Macros that conditionally generate code

2019-03-06 Thread David Storrs
On Wed, Mar 6, 2019 at 11:31 PM Sorawee Porncharoenwase wrote: > > Isn’t this because of hygienity in general? *headdesk* Of course. Thanks, I should have recognized that. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from t

Re: [racket-users] Macros that conditionally generate code

2019-03-06 Thread Sorawee Porncharoenwase
For your case: #lang racket (require (for-syntax syntax/parse racket/syntax)) (define-syntax (foo stx) (syntax-parse stx [(foo name val (~optional (~seq #:make-double? make-double?:boolean))) (with-syntax* ([NAME (datum->syntax stx 'doubleup)]

Re: [racket-users] Macros that conditionally generate code

2019-03-06 Thread Sorawee Porncharoenwase
Isn’t this because of hygienity in general? For example: #lang racket (define-syntax (foo stx) (syntax-case stx () [(_) #'(define doubleup 1)])) (foo) doubleup ; unbound id doesn’t define doubleup. While the below code does: #lang racket (define-syntax (foo stx) (syntax-case stx ()

[racket-users] Macros that conditionally generate code

2019-03-06 Thread David Storrs
I would like to write a macro that accepts an optional keyword argument. If the argument is missing, or if it is present and has a true value, then some code will be generated. Otherwise, nothing is done. This was my best attempt: #lang racket (require (for-syntax syntax/parse)) (define-syntax