m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FYI: 5-gary-macro-formal-parameter-first-cut.patch


From: gary
Subject: Re: FYI: 5-gary-macro-formal-parameter-first-cut.patch
Date: Thu, 12 Jun 2003 12:33:18 +0100
User-agent: Demon-WebMail/2.0

address@hidden wrote:
> 
>  >> Just applied to HEAD.
>  >> Most of this is okay, and it certainly works.  But it strikes me that
>  >> it would be much more elegant to pushdef the values named by the
>  >> formal parameter list for the duration of the expansion of a macro.
>  >> In the body of a macro the parameters would be referenced by name
>  >> (without a leading $) and there would be dynamic scoping since nested
>  >> macros could reference parameters from their parents.
> 
>  >> define(`foo(bar)', `blah: bar')
>  >> foo(`baz')
>  >> =>blah: baz
>  >> define(`quux(blah)', `quux: blah; foo(`argh')')
>  >> quux(`baz')
>  >> =>quux: baz; baz: argh
> 
>  >> Comments?
> 
>  > I hate dynamic scoping :(  But it's already the rule here, so...

It just requires a mental gear shift -- much like using M4 at all :-)  And as 
you say it seems more fitting to the style of M4.

>  > Nice idea, but I need more time to think about this.
> 
> Not a good idea.  $1 etc. have a completely different behavior, of
> course.
> 
> Consider:
> 
>         define([foo], [[[$1]]])
>         foo([bar])
> 
> That would never work with pushdef.  That's also why I'd like to
> encourage a $ mark for the arguments, they are special beasts.

That's how it works in CVS already (hmm actually it seems to be broken atm):

    define('foo(baz)',```$baz''')
    foo(`bar')
    => `bar'

Numbered params will still work when this sort of thing is needed, so with
parameters bound (pushdefed) at macro call time we could use:

    define(`q',```$1''')
    define(`foo(baz)', `q(baz)')
    foo(`bar')
    =>`bar'

> And actually, I also think addressing this issue should be done
> simultaneously with prototyping, i.e., m4 should complain when there
> is not the right number of arguments etc.

Agreed, I was aiming here too.

> But then we need to support multi-prototypes macros.  Maybe we should
> have a look at Perl?
> 
>      define([foo($a, $b; $c, $d; $e)], ...
>
> Would support 2, 4 or 5 arguments.  Hm.  How about 0?  And how about
> n-ary macros?

Ick!  I hate perl ;-)  I was thinking more like common lisp:

    define(`foo(a, b, &optional (c bar), (d baz), &rest e)', ...)

> There is plenty of things to think about.  A module aware M4 is truly
> needed though...

Indeed.  I wanted something fun to play with to get my head back into the
code -- It's been over a year since I touched it. I'll pull it out into a
module or something and begin tidying and testing presently.

We can pick this conversation up after 1.5, and figure out the details then.

Cheers,
        Gary.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]