I have a routine with several input arguments and one
output argument.  I want to write a macro to wrap my
output argument such that I can pass the results of
my input arguments to my output argument.  (See below)

I have this working with an explicit renaming macro,
but this is overkill.  I could find myself capturing
variables other than my input arguments.

I'd like to rewrite this macro as an implicit renaming
macro, which seems to require that I traverse form and
insert (inject arg1) wherever I find arg1, and to do
the same for arg2.

I do not otherwise need to transform the symbolic
expression bound to output.  Is there some idiomatic
way to traverse a tree and perform a set of replacement
operations on matching leaves?  

  (define (doit #!key arg1 arg2 output)
    (output arg1: arg1 arg2: arg2))

  ; er-macro-transformer works, but it might capture
  ; more than arg1, arg2.  Can I rewrite this to
  ; explicitely inject arg1 and arg2?
  ;
  (define-syntax do-output
    (er-macro-transformer
      (lambda (form rename compare?)
        `(lambda (#!key arg1 arg2)
           (list ,@(cdr form))))))

  >>> (doit arg1: "hello"
            arg2: "world"
            output: (do-output arg1 arg2))
  => ("hello world")

Thank you,

-Alan
-- 
my personal website: http://c0redump.org/

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to