Re: [Chicken-users] help with implicit renaming macro

2013-11-11 Thread Alan Post
On Mon, Nov 11, 2013 at 09:36:48PM +0100, Peter Bex wrote:
> On Mon, Nov 11, 2013 at 01:22:40PM -0701, Alan Post wrote:
> > 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.
> 
> Hi Alan,
> 
> Actually, you only need to inject the args where they
> are introduced.  This will cause them to be bound
> unhygienically, which means they'll capture any local
> variables with that same literal name.
> 
> So unless I'm completely misunderstanding what you're
> trying to do, this will suffice:
> 
> (define-syntax do-output 
>   (ir-macro-transformer
> (lambda (e i c)
>   `(lambda (#!key ,(i 'arg1) ,(i 'arg2))
>  (list ,@(cdr e))
> 
> > 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?  
> 
> SSAX has "foldts" which can fold over trees, but I think
> it's overkill to load an XML library just to transform your
> macros :)
> 
> Finally, you might want to take a look at some of Juergen Lorenz's
> eggs, they provide some tools to deal with low-level macros a bit
> more conveniently.
> 

Aha, I missed the quote to the inject parameter, got an error about
arg1, and assumed it was happening during expansion to report an
unbound variable.  pebkac.

This does indeed work, fantastic.  Really stellar feature, ir-macros.
I have the most experience with defmacro, and it took me some time
to come to terms with define-syntax/syntax-rules, though the vast
majority of my macros fit easily and comfortably in that rubric.

This was the first time in a long while I've wanted to do something
more than simple transformation.  I appreciate your guidance here!

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

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


Re: [Chicken-users] help with implicit renaming macro

2013-11-11 Thread Peter Bex
On Mon, Nov 11, 2013 at 01:22:40PM -0701, Alan Post wrote:
> 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.

Hi Alan,

Actually, you only need to inject the args where they
are introduced.  This will cause them to be bound
unhygienically, which means they'll capture any local
variables with that same literal name.

So unless I'm completely misunderstanding what you're
trying to do, this will suffice:

(define-syntax do-output 
  (ir-macro-transformer
(lambda (e i c)
  `(lambda (#!key ,(i 'arg1) ,(i 'arg2))
 (list ,@(cdr e))

> 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?  

SSAX has "foldts" which can fold over trees, but I think
it's overkill to load an XML library just to transform your
macros :)

Finally, you might want to take a look at some of Juergen Lorenz's
eggs, they provide some tools to deal with low-level macros a bit
more conveniently.

Cheers,
Peter
-- 
http://www.more-magic.net

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


[Chicken-users] help with implicit renaming macro

2013-11-11 Thread Alan Post
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