Luke Palmer wrote:
I'm not quite sure I follow you (I'm not familiar with that pattern).
But the macromethod I imagine is the non-polymorphic one, and the one
it expands to is the polymorphic one, if I'm guessing correctly.  And
you certianly could do that.

yes: http://patterndigest.com/patterns/TemplateMethod.html


But the actual I<parsing> could not be
polymorphic.  Thus, this wouldn't work:

    my $db = new Database;
    $db.select ...

Because the compiler [may] not know that $db is a Database until
runtime, after it's been parsed.  However, this could work:

    my Database $db = new Database;
    $db.select ...

To a large extent, this depends on how powerful the type-inference mechanisms are. In theory, if MyDatabase.new "returns Database", then the type of $db can be inferred. Even if the return type is not explicitly defined, we can look in the method-body, and see that its constructing/returning an object of base-type Database.


But you're right, there are situations where the (base) type might not be knowable: and these could result in syntax errors.

So, what I'm essentially saying is that C<macromethod> doesn't buy you
much save syntactic sugar.  Perhaps you can give a concrete
counterexample?

I admit that I have a sweet-tooth: I like syntactic sugar ;-). And I'm one of those environmentalists who don't like (namespace) pollution.


The sugar I'm using here is to go from

  $db.do_sql("select * from Foo");
to
  $db.select * from Foo;

I'm sure there is nice way to represent this with a leading keyword: but one of the things that Perl6 is doing (over perl5) is to make (almost) everything callable as methods. Thus if we allow (as a standard macro -- though a macromethod would also support it)

select $db: * from Foo;

then we should also allow the method-call syntax. I'll admit that this is one of those cases where the user already knows that there's some magic happenning -- that "select" is introducing a new syntax -- but it would be nice to keep the invocant part looking like Perl6 code.

Perhaps I should back off a bit: Perl6 *will* be powerful enough support the "Macros::macromethod" module, so perhaps I'll be able to write it in a year's time, or so. It'll be a good test of the extensability mechanisms.


Dave. -- http://dave.whipp.name



Reply via email to