On Thursday, March 31, 2016 at 1:00:55 AM UTC-7, [email protected] 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 > > > > (define conditional-actions > > (list (cons (lambda () (= 2 (+ 1 1))) > > (lambda () (display "first!\n"))) > > (cons (lambda () (= 42 (* 2 21))) > > (lambda () (display "second!\n"))))) > > > > (define (fun-now lst) > > (for-each (lambda (pair) > > (and ((car pair)) > > ((cdr pair)))) > > lst)) > > > > (display "fun-now...\n") > > (fun-now conditional-actions) > > > > (define (make-fun-for-later lst) > > (lambda () > > (for-each (lambda (pair) > > (and ((car pair)) > > ((cdr pair)))) > > lst))) > > > > (display "make-fun-for-later...\n") > > (define fun-later (make-fun-for-later conditional-actions)) > > (display "fun-later...\n") > > (fun-later) > > ---- END CODE ---- > > > > ---- BEGIN OUTPUT ---- > > fun-now... > > first! > > second! > > make-fun-for-later... > > fun-later... > > first! > > second! > > ---- END OUTPUT ---- > > > > I gave this kind of example of using procedures because I don't know > > whether you're already familiar with how to use procedures/closures like > > this. > > > > Neil V. > > yes this is the effect I was looking for, but fun-now and fun-later are > interpreting the conditional actions while I wanted to generate the code for > them.
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. -- 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.

