develooper Front page | perl.perl6.users | Postings from March 2021

Re: 'CALL-ME' Math problem?

Thread Previous | Thread Next
From:
Vadim Belman
Date:
March 2, 2021 15:29
Subject:
Re: 'CALL-ME' Math problem?
Message ID:
FAE58F6C-E244-4470-B3F9-F46E985334D6@lflat.org

Not in this case. The error happens at run-time. Syntactically the expression is a valid one because `5(...)` is interpreted as an invocation. Raku implements invocation protocol a part of which is method 'CALL-ME' defined on a class:

class Foo {
    method CALL-ME(|c) { say "Foo invoked with {c.raku}" } 
}
Foo(42, :foo(13));
Foo.new().();

Note that the protocol works for both a type object and its instantiation. This is what is basically happens in the case of `5(...)`: it falls back to `Int` and tries to invoke `CALL-ME` on it. One could say that it makes no sense, but an example with adding a fallback method has been already provided here. And here is another one follows:

my $foo = 5 but role { method CALL-ME(|c) { say "Int with ", c.raku } }; $foo(13);

The currently produced error, unfortunately, is confusing for beginners. But as soon as one gains more experience with Raku it makes clear sense instantly.

Best regards,
Vadim Belman

> On Mar 2, 2021, at 9:26 AM, Parrot Raiser <1parrota@gmail.com> wrote:
> 
>> Doing so would, of course, be a very bad idea.  But still, you _could_.
> 
> Something of an understatement, I think. :-)*
> 
> Seriously, this made me wonder if inscrutable error messages might be
> clarifed by a (reverse) trace of the last few steps in parsing. That
> would show you what the compiler thought ir was doing.
> 
> Would that be a) reasonably practical to implement, and b)
> sufficiently useful to justify the effort?
> 


Thread Previous | 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