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
From:
Luke Palmer
Date:
March 30, 2005 13:42
Subject:
Re: Parameter and trait questions - just how 'only' _is_ 'read-only'?
Message ID:
20050330214521.GB301@navi.cx
Thomas Sandlaß writes:
> 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.

Hey, no pointing out errors when I'm arguing! :-)

Yes, given a s/sub/method/ it is valid Perl 6. ;-).

As for the rest of this message, see my coming reply to Aaron's message,
which points out that we're beginning to talk past each other because
the original context has been lost.

Luke

> >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 = DoubleCodeProxy.new; # needs DoubleCodeProxy <: CodeProxy
> 
> $cp.code = sub ($x, +$y = "unknown") { say "x = $x, y = $y" };
> 
> $cp.call( "first", b => "second" ); # prints "x = first, y = second"
> $cp.call( "one" );                  # prints "x = one, y = unknown"
> 
> $t = $cp.code;
> 
> $cp.code = sub () { say "void" };  # no problem, type is Code
> $cp.call( "X" ); # gives runtime error on closure in $.code
> 
> $cp.code = $t;
> 
> $cp.call(); # compile error: too few args
> $cp.call( 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
> 
> $cp.call( 1|2|3 ); # autothreads??? I leave that to Damian :)
> -- 
> TSa (Thomas Sandlaß)
> 

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