On Tue, Jun 14, 2005 at 02:06:37PM +0200, BÁRTHÁZI András wrote:
: Hi,
: 
: As I know, for binding, you can use the := operator, and just this:
: 
:   $a := $b;
: 
: I would like to make a proposal, based on Ruby[1]:
: 
:   alias $a, $b;

You can always write a macro that does that.

: It's a fun:
: 
:   sub newline {
:       "\n" x $_;
:   }
: 
:   alias newlines, newline;

At one point we had a macro variant for single words:

    word enters {'newline'};

But it's not clear which syntactic categories pay attention to that.
It's obvious that your intent is to alias a method name, here, but
that's not at all obvious to the compiler.  Most simple macros remap
terms, not method names, which are a subset of postfix operators that
require the dot.

: So you can write:
: 
:   print 5.enters;
: 
: Currently, you have to write it a more "uglier" way:
: 
:   my &newlines := &newline;

That won't work on a method name anyway unless you do it in the
dispatch class.

: Anyway, char '&' is really neccesary there? It should work w/o it, too, as 
: I think. Now - in Pugs - it doesn't.

The point of the sigils is to help keep the namespaces and syntactic
categories straight, and to indicate you're talking about the actual
variable object rather than just a name.  Since you're merely trying
to remap the name here and not the object (which isn't even a variable
in your own package), the use of & is going to be inappropriate in
any event.  What you're really looking for is some kind of macro
based syntactic sugar that maps the appropriate syntactic category.
Maybe something based on this:

    my macro postfix:<enters> { 'newline' }

There's some possibilility of syntactic sugar resembling:

    my postfix:<enters> ::= <newline>;

But Perl 6 is not going to encourage the C-preprocessor mindset of
completely divorcing the meaning of identifiers from their syntactic
context.  In other words, you can't wildcard the syntactic category:

    *:<enters> ::= <newline>;

You'll have to write your own macro if you want to do that.

Larry

Reply via email to