develooper Front page | perl.perl6.language | Postings from July 2005

User-defined infix subs/methods?

Thread Next
From:
Autrijus Tang
Date:
July 9, 2005 08:35
Subject:
User-defined infix subs/methods?
Message ID:
20050709153423.GA35371@aut.dyndns.org
In Pugs's ext/Set/lib/Set.pm, there are a number of user-defined
infix operators.  To avoid unicode in mails, I'll use a hypothetical
&infix:<===> as the operator name.

Consider the sub case:

    class Set;
    sub infix:<===> (Set $x, Set $y) { ... }

Is it correct that this line:

    Set.new === Set.new

Only works when the &infix:<===> function is in scope?  That is, one
would need to add `is export` to its declaration for the user of the
Set module to access to this operator.

Does the same holds for `multi sub` as well?

What if this is expressed as a method:

    class Set;
    method infix:<===> (Set $y) { ... }

Does it also need `is export`?  If not, how does the parser know that
the === is a valid operator name, without the ability to deduce the type
of its left hand side object?  If yes, does it simply fail at runtime
if the left hand side has no infix:<===> defined?  Exporting a method
is a novel concept to me, too.

Thanks,
/Autrijus/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About