On 02/04/2011 08:51 PM, Solomon Foster wrote:
> On Fri, Feb 4, 2011 at 7:29 AM, Moritz Lenz via RT
> <[email protected]> wrote:
>> Am 04.02.2011 05:04, schrieb Solomon Foster (via RT):
>>> # New Ticket Created by Solomon Foster
>>> # Please include the string: [perl #83356]
>>> # in the subject line of all future correspondence about this issue.
>>> #<URL: http://rt.perl.org/rt3/Ticket/Display.html?id=83356>
>>>
>>>
>>> If I have this:
>>>
>>> class A {
>>> multi sub infix:<+>(A $a, A $b) is export { say "hello" }
>>> }
>>>
>>> my A $a .= new;
>>> say ($a + $a).perl;
>>>
>>> I get
>>>
>>> Can't take numeric value for object of type A
>>> in 'Any::Numeric' at line 1456:CORE.setting
>>> in 'infix:<+>' at line 7454:CORE.setting
>>> in main program body at line 8:frip.pl
>>
>> That's correct behaviour. Multis are lexical by default (just like
>> ordinary only-subs), so the availability of the new infix:<+> outside
>> the class would be a bug.
>
> But "is export" means it is available outside the class anywhere this
> file is "use"d.
More precisely, everywhere where this multi is imported. 'use A;' by
default imports all the 'is export' and 'is export(:DEFAULT)' routines.
The "is export" doesn't magically make it available in an outer scope of
the same file.
> Is it really intended that it is available outside
> the class everywhere except the file it is defined in?
Yes. If not imported, normal lexical scoping applies.
> And if so, how
> should it be defined so that the multi is visible elsewhere in that
> file?
Just define it in the scope where you want it to be visible.
Or import it (NYI in rakudo):
class A {
multi infix:<+>($a, $b) is export { ... }
}
import A;
# use it here.