Whilst I've been hacking the perl 6 scheme interpreter I've found
myself using code like the following
method get_token( $self: ) {
given $self.get_char {
when !defined { fail IOException: msg=> "EOF" }
when /\s/ { $self.get_token }
when '(' { $the_left_paren }
when ')' { $the_right_paren }
when '"' { $self.read_string }
when /\d/ { $self.read_number($_) }
default { $self.read_identifier($_) }
}
}
Initially, that got written as:
method get_token {
given .get_char {
...
default { # Hang on, how do I call a method on myself now?
}
}
}
The issue here is that, if you ever want to use a topicalizer inside a
method definition, and you're going to want to call a method on
yourself from inside the scope of that topicalizer then you can't
really make use of implicit self references.
And because topicalizers are such a powerful tool (believe me; I don't
think I've written a single 'if' statement anywhere in the scheme
interpreter, it's starting to feel clumsy), you're going to end up
with almost all your method declarations looking like:
method foo($self: ... ) {...}
So, is there any chance that we'll be able to do:
class ical {
use object_name '$self';
method ical {
given $self.ology {
... { $self.ish }
}
}
}
(I'm sure we'll be able to write 'object_name', I'm just hoping that
it'll come as part of the core distribution)
--
Piers
"It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite."
-- Jane Austen?