develooper Front page | perl.perl6.language | Postings from August 2001

Re: Will subroutine signatures apply to methods in Perl6

Thread Previous | Thread Next
Uri Guttman
August 24, 2001 20:56
Re: Will subroutine signatures apply to methods in Perl6
Message ID:
>>>>> "BD" == Brent Dax <> writes:

  BD> # From: Uri Guttman []
  BD> # 	use strict 'typing' ;
  BD> #
  BD> # 	my $foo = ;
  BD> #
  BD> # that fails at compile time.
  BD> #
  BD> # 	my Dog $spot = ;
  BD> #
  BD> # that is ok.
  BD> #
  BD> # 	my Canine $spot = ;
  BD> #
  BD> # that is ok if Dog ISA Canine. $spot could be assigned a Dog or a Cat
  BD> #
  BD> # 	my $foo = foo() ;
  BD> #
  BD> # is fine too, since no compile time detection of OO values is made.

  BD> Two other possibilities:

  BD> 1. Typing is required on variables which method calls are invoked on:

  BD> 	use strict 'typing';		#don't look at the keyboard!  :^)
  BD> 	my Dog $;		#ok
  BD> 	my Dog $fido=new Dog;		#ok (indirect-object is staying, right?)
  BD> 	my $;			#ok at this point...

  BD> 	$spot.bark();			#ok
  BD> 	$fido.bark();			#ok
  BD> 	$rex.bark();			#ERROR: $rex isn't declared to hold an object

is that a compile time or runtime error? i don't think you can make it
compile time since $rex can be assigned a real object and still call the
bark method.

  BD> 2. A 'normal' type:

  BD> 	use strict 'typing';
  BD> 	my Dog $;	#ok
  BD> 	my $foo="bar";		#bad--no type on $foo
  BD> 	my val $baz="quux";	#ok

  BD> I'm not necessarily suggesting 'val' as a type, however--that's just a
  BD> placeholder for whatever we would choose.

i don't like that. plain perl scalars should always be allowed even when
while odd pragmata are in effect.

  BD> I don't see this as being one of the 'normal' strictures--this
  BD> would be in the @EXPORT_OK array, not @EXPORT (if strict used
  BD> Exporter, that is).  You'd have to turn it on explicitly.

if it has the meaning i proposed, it could be under the default set in
use strict. but it deosn't have to be.

  BD> Could we use this so that we don't have to use 'ref' (or its moral
  BD> equivalent) in method lookups?  In other words, if $spot is declared to
  BD> hold a Dog, can we assume that it does, thus skipping the check with
  BD> 'ref' normally used for method dispatch?  Would this even buy us
  BD> anything?  Why am I asking myself these questions?  Why are the
  BD> orderlies putting me in a white truck?

no, that won't work. you can always bypass that at runtime in too many
ways. as damian stated, runtime checks for objects are always in
effect. if a method isn't found or handled by AUTOLOAD or something it
is fatal (unless caught, of course). the method itself will always need
to check its arguments if it cares about whether a class or object is
the invocant (i like that word. thanx, damian!).


Uri Guttman  ---------  ----------
SYStems ARCHitecture and Stem Development ------
Search or Offer Perl Jobs  --------------------------

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