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

User-defined infix subs/methods?

Thread Next
Autrijus Tang
July 9, 2005 08:35
User-defined infix subs/methods?
Message ID:
In Pugs's ext/Set/lib/, 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: ===

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.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About