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

Re: Parameter and trait questions - just how 'only' _is_ 'read-only'?

Thread Previous | Thread Next
March 31, 2005 08:35
Re: Parameter and trait questions - just how 'only' _is_ 'read-only'?
Message ID:
Miroslav Silovic wrote:

> Remember, you can even change the class of instanced objects using 
> 'does' (or 'but', but it'll at least copy the object). And as the 
> example above shows, this is statically intractable - it can happen in a 
> sub in a different autoloaded module.

Sorry this is a well established fact in this thread. If unspecificity
is what you want than you use 'my $a;' and the compiler happily parses
'$a.meth()' purely syntactically and generates code for dynamic lookup
and potential exception throwing.

Aaron's and my point is the reverse: what do we gain if the same applies
when we kindly announce that $a should do X'ish things only. That of course
includes late bound fancy versions of methods from the interface of X. If
there's no difference why bother to make declarations?

This whole thread is about semantics close to syntax. I mean we know that
"everything with a dot is a method" which syntactically makes dot the infix
method sigil or some such.  But I want the compiler to do a bit more than
just extracting the string after the dot from my source code and stash it
in some namespace when I requested the constraint X.

Is typing optional in the sense that it is no syntax error but
otherwise ignored? To me this is pain but no gain :(

BTW, is 'my ::X $a;' introducing X as unspecific as it could be?
Just occupying the syntactic slot of a type? That could be usefull
to start in an explorational style and eventually use the PTE
(P(arrot|erl6) Type Engine) to infer what X should look like.
I really see the PTE as the twin of the PGE---and no Perl hacker
disavows the power of regular expressions and parsers ;)

> Also, what do you want to do if you actually want $a.meth() to throw a 
> catchable exception if $a doesn't implement meth? It's what many OO 
> languages do. In fact, I can't recall a single OO language that isn't 
> derived from C++ that does /not/ just throw a runtime exception on 
> unknown method.

Well that would just be "role X { method meth() {...} }" by virtue of
the nada operator---whatever exception it throws and how much it tells
about X::meth().
TSa (Thomas SandlaƟ)

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