Re: [racket-users] How to call a macro on each element of a list

2016-04-04 Thread 'John Clements' via Racket Users
> On Mar 31, 2016, at 3:31 PM, cna...@cs.washington.edu wrote: > > On Thursday, March 31, 2016 at 1:00:55 AM UTC-7, cna...@cs.washington.edu > wrote: >> On Wednesday, March 30, 2016 at 5:37:08 PM UTC-7, Neil Van Dyke wrote: > > I found a solution to my problem. I realised that it was better to

Re: [racket-users] How to call a macro on each element of a list

2016-03-31 Thread Neil Van Dyke
I found a solution to my problem. I realised that it was better to use a function instead of a macro to generate the code. I created a list and appended the different parts of the code I wanted to generate in bottom up manner. eval-ing the list can run the code. If that works for you, good.

Re: [racket-users] How to call a macro on each element of a list

2016-03-31 Thread cnandi
On Thursday, March 31, 2016 at 1:00:55 AM UTC-7, cna...@cs.washington.edu wrote: > On Wednesday, March 30, 2016 at 5:37:08 PM UTC-7, Neil Van Dyke wrote: > > Does either the below `fun-now` or `make-fun-for-later` do what you want? > > > > BEGIN CODE > > #lang racket/base > > > > (defin

Re: [racket-users] How to call a macro on each element of a list

2016-03-31 Thread cnandi
On Wednesday, March 30, 2016 at 5:37:08 PM UTC-7, Neil Van Dyke wrote: > Does either the below `fun-now` or `make-fun-for-later` do what you want? > > BEGIN CODE > #lang racket/base > > (define conditional-actions >(list (cons (lambda () (= 2 (+ 1 1))) >(lambda () (d

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Neil Van Dyke
Does either the below `fun-now` or `make-fun-for-later` do what you want? BEGIN CODE #lang racket/base (define conditional-actions (list (cons (lambda () (= 2 (+ 1 1))) (lambda () (display "first!\n"))) (cons (lambda () (= 42 (* 2 21))) (lambda ()

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread cnandi
On Wednesday, March 30, 2016 at 2:21:52 PM UTC-7, Neil Van Dyke wrote: > cna...@cs.washington.edu wrote on 03/30/2016 05:11 PM: > > I still need to explicitly pass all the arguments to mysyn such as: > > (mysyn 1 2 3). Is there a way to pass a list l by its name and not its > > values. > > For ins

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Alexis King
> However, my problem is still not resolved because in all the suggestions > above, I still need to explicitly pass all the arguments to mysyn such as: > (mysyn 1 2 3). Is there a way to pass a list l by its name and not its > values. > For instance, If l is '(1 2 3) > I want to be able to cal

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Neil Van Dyke
cna...@cs.washington.edu wrote on 03/30/2016 05:11 PM: I still need to explicitly pass all the arguments to mysyn such as: (mysyn 1 2 3). Is there a way to pass a list l by its name and not its values. For instance, If l is '(1 2 3) I want to be able to call the macro as (mysyn l) and not (mysyn

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread cnandi
On Wednesday, March 30, 2016 at 1:45:09 PM UTC-7, Robby Findler wrote: > Perhaps we should improve the syntax-parse documentation? I found the > overview and examples to be pretty good, tho. > > Robby > > > On Wed, Mar 30, 2016 at 3:42 PM, Neil Van Dyke wrote: > > Oops, I usually end up typing

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Neil Van Dyke
Robby Findler wrote on 03/30/2016 04:45 PM: Perhaps we should improve the syntax-parse documentation? I found the overview and examples to be pretty good, tho. When the goal is to teach syntax extension, maybe it would make sense to pick *one* syntax extension form to introduce to people, and

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Robby Findler
Perhaps we should improve the syntax-parse documentation? I found the overview and examples to be pretty good, tho. Robby On Wed, Mar 30, 2016 at 3:42 PM, Neil Van Dyke wrote: > Oops, I usually end up typing one of the names wrong. Summary: > > * syntax-case -- good one to start with, smooth p

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Neil Van Dyke
Oops, I usually end up typing one of the names wrong. Summary: * syntax-case -- good one to start with, smooth path to syntax-parse * syntax-parse -- best thing ever, but documentation is intimidating, so maybe start with syntax-case instead * syntax-rules -- old, limited, no smooth path, yo

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Vincent St-Amour
A few things: 1. You're mixing elements of `syntax-rules` and `syntax-case` / `syntax-parse`. The former has an implicit template in its right-hand side, so you don't need the `#``, whereas you do with `syntax-case` / `syntax-parse`. 2. If you want this to define a function (as I'm guess

Re: [racket-users] How to call a macro on each element of a list

2016-03-30 Thread Neil Van Dyke
You had the right idea, if you're using `syntax-rules`, but there were a few small problems: BEGIN #lang racket (define-syntax mysyn (syntax-rules () ((_ NAME ELEMENTn ...) (define (NAME) (display ELEMENTn) ... (mysyn fun 1 2 3) (fun) END But, if you

[racket-users] How to call a macro on each element of a list

2016-03-30 Thread cnandi
Consider a toy macro defined as: (define-syntax mysyn (syntax-rules(fun) [(mysyn element ...) (begin #`(define fun (display element)...))])) and a list: (define l '(1 2 3)) Is there a way to call the macro like so: (mysyn l). When I try this, the syntax ob