On Dec 1, 2007 2:22 PM, Joshua ben Jore <[EMAIL PROTECTED]> wrote:
> On Dec 1, 2007 8:51 AM, Jenda Krynicky <[EMAIL PROTECTED]> wrote:
> > From:                   "David Nicol" <[EMAIL PROTECTED]>
> > > On Nov 30, 2007 7:24 PM, Jenda Krynicky <[EMAIL PROTECTED]> wrote:
> > > > I'm missing the reason-for-being of the module it its docs. I read
> > > > the whole documentation and the test script and I still don't get it.
> > > >
> > > > What is it supposed to be used for?
> > > >
> > > > Sorry, Jenda
> > >
> > >  polymorphic functions / more complex prototypes
> >
> > Any examples?

Currently when you want to have a sub act differently depending on
how many arguments are supplied to it, rather than the naive

   sub  poly($) { print "got one arg, @_\n" }
   sub  poly($$) { print "got two args, @_\n" }

working as intended, you have to do something like

   sub  poly($;$) {
          @_ == 1 and return print "got one arg, @_\n";
          print "got two args, @_\n"
   }

Using Macrame, you can do

   sub  _poly1arg($) { print "got one arg, @_\n" }
   sub  _poly2arg($$) { print "got two args, @_\n" }
   macro poly(one,two) { _poly2arg(one,two) }
   macro poly(one) { _poly1arg(one) }
   macro poly one,two { _poly2arg(one,two) }
   macro poly one { _poly1arg(one) }

> > >  creating new syntax without dealing directly with unlexed source

internal syntax for Macrame, for example.  A good deal of thought went
into selecting "everything up to and including the next semicolon" as the
signature for EXPAND.  This means that if you  want EXPAND to look the
same as BEGIN, END, INIT, et cetera, you could define

   macro EXPAND '{body}' {EXPAND body ;}

Macrame is envisioned as the basis for the TERN project, which intends to
rewrite perl in perl by defining a set of macros that rewrite more complex
source code constructions using simpler ones (the motivations for this
project aren't very strong, which is how it has been largely backburnered
for a very long time)

For instance, the trailing if syntax

     print "flag true\n" if $flag;

might  be expressable using standard if, so that a macro could be defined
that would rewrite the above line to

    $flag and print "flag true\n";

at the source filtering pass rather than later on where that is done now.  That
is not a really good example for version 0.08 because there is no way to
specify either an infix macro or a greedy macro argument at this time; both
of those features are on the wishlist.

Most features proposed in 2000 on the perl6 language brainstorming
mailing list would be suitable candidates for implemetnation using macros

A feature I believe can be added using 0.08 syntax is the idea of having
"my" create a reference

     macro my \$alias = \$Item; {
        my $alias;
        $alias = \$item;
        macro alias { {NOMACROS $alias} } # from here on, $alias is
"really" ${$alias}
    }

which may sort of work at this point.


> > Looking at the KNOWN BUGS it doesn't look like this works too well.
> > Any examples of a "new syntax" that you would like to be able to
> > create? So that we can see how close would we be able to get without
> > using source filters.

Macrame _is_ a source filter; it provides a filtering syntax that abstracts away
some parsing steps.

> > >  inlining small oft-used code snippets without all those pesky function 
> > > calls
> >
> > "Premature optimization is the root of all evil."
> > OTOH, being able to inline functions could be nice, yes.

Yes, with Macrame you can have both inlined data access and detail hiding.

> You ought to check out Scott Walter's Code::Splice then. When I last
> talked to him it worked well when applied at the statement level. That
> is, your insertion point is at a statement level and I gather it'll
> take a full sub and inline it. And other stuff but I forget what.

Macrame is not limited to statement or expression level; I will include
this in  the see also section in 0.09.

David Nicol
-- 
wheels reinvented while-U-wait

Reply via email to