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 30, 2005 12:50
Re: Parameter and trait questions - just how 'only' _is_ 'read-only'?
Message ID:
Luke Palmer wrote:
>     class CodeProxy {
>         has Code $.code is rw;
>         sub call ($a) {
>             $.code($a);
>         }
>     }
> This is valid Perl 6,

Hmm, a sub in a class? I guess that should be a method. OTOH a
class is just a funny module, so might be OK. But that is the
syntax realm.

> and anyone who says otherwise (because of type
> signatures) is changing the Perl philosophy too much to be taken
> seriously.  Now, tell me at compile time whether the call inside `call`
> is valid.

Ups, before we start talking past each other: I think a type system
is just a tool that reminds you to your declarations. No declarations,
no reminder, it's that simple. I would like the typing of $.code as Code
to be necessary to apply the .() invocation operator on it. The rest is
deferred to runtime if that is what you want.

And I'm completly unsure how much parrot and/or perl revert back into
compile state when you bring in new source code at runtime. Or how
much load time activity is needed for a byte code file.

The question if instances of DoubleCodeProxy are subtypes of instances
of CodeProxy boils down to the question if ($) <: ($, +$) with <: beeing
the subtype relation. Is that the right siglet syntax? Since named-only
parameters are optional the relation holds. This subtype relation allows:

my CodeProxy $cp =; # needs DoubleCodeProxy <: CodeProxy

$cp.code = sub ($x, +$y = "unknown") { say "x = $x, y = $y" };

$ "first", b => "second" ); # prints "x = first, y = second"
$ "one" );                  # prints "x = one, y = unknown"

$t = $cp.code;

$cp.code = sub () { say "void" };  # no problem, type is Code
$ "X" ); # gives runtime error on closure in $.code

$cp.code = $t;

$; # compile error: too few args
$ 1, 2 ); # compile error: too many positional args
$cp.blahh( 23 ); # compile error/warning: no such method declared

method CodeProxy::blubber(: $z ) { ... }

$cp.blubber( 42 ); # could die on ... at runtime if no .blubber autoloaded

$ 1|2|3 ); # autothreads??? I leave that to Damian :)
TSa (Thomas SandlaƟ)

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