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

RE: Will subroutine signatures apply to methods in Perl6

Thread Previous | Thread Next
From:
Brent Dax
Date:
August 25, 2001 02:57
Subject:
RE: Will subroutine signatures apply to methods in Perl6
Message ID:
FJELLKOPEAGHOOODKEDPEEHFCEAA.brentdax@cpan.org

# -----Original Message-----
# From: Uri Guttman [mailto:uri@sysarch.com]
# Sent: Friday, August 24, 2001 4:09 PM
# To: damian@conway.org
# Cc: perl6-language@perl.org
# Subject: Re: Will subroutine signatures apply to methods in Perl6
#
#
# >>>>> "DC" == Damian Conway <damian@mail.csse.monash.edu.au> writes:
#
#   DC> One might also envisage a C<use strict 'typing'> pragma
# to require
#   DC> that all lexicals be typed.
#
# do you mean lexical params in a sub signature? or all lexicals in the
# current scope which contains the pragma?
#
# required typing for all lexicals feels too strong. many lexicals are
# just ordinary scalars and don't type well unless we require an
# int/string/float/ref type.
#
# what about making that mean that any scalar being assigned a
# method call
# (compile time checked only), must have a type? it would not
# be too broad
# and should be simple to check and it has useful behavior.
#
# 	use strict 'typing' ;
#
# 	my $foo = Dog.new() ;
#
# that fails at compile time.
#
# 	my Dog $spot = Dog.new() ;
#
# that is ok.
#
# 	my Canine $spot = Dog.new() ;
#
# that is ok if Dog ISA Canine. $spot could be assigned a Dog or a Cat
#
# 	my $foo = foo() ;
#
# is fine too, since no compile time detection of OO values is made.

Two other possibilities:

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

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

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

	my $class="Dog";
	my Dog $butch=$class.new;	#lost in the shuffle
	#of course, you could easily do this:

	my Dog $sparky;
	{
		no strict 'typing';
		$sparky=$class.new;	#ok, since you switched off strict typing
	}

2. A 'normal' type:

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

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

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

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

--Brent Dax
brentdax1@earthlink.net


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