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

How do you say another_sub(@_) in perl 6?

Thread Next
From:
Yuval Kogman
Date:
August 28, 2005 01:58
Subject:
How do you say another_sub(@_) in perl 6?
Hi,

What is the "correct" way to do pass through args?

In perl 5 we would do:

	sub whatever {
		...
		nested_call(@_);
		...
	}

but slurpy args are undesireable, since they are lossy:

	data loss - shape of input parameters is indeterminate:

		sub foo (*@args) { ... };

		my $scalar = "Bah";
		my @array = <foo bar>;

		foo($scalar, @array); # gets <Bah foo bar>
	
	type information loss - the types signature of the callee is
	masked

A possible solution:

	sub foo will call &other { # type signature copied, lexical
	# scope of foo changed to have 'my &other = &other.assuming(...)'
		my $return = other();

		@?PARAMS; # contains a list of positionals and nameds,
		# without any flattenning, and without the shape being lost
	}

And more interestingly, for generic programming:

	sub foo (&delegate is called) {
		delegate();
	}


my &curried = foo.assuming(&some_sub);

&curried.signature; # this is already available

&foo.signature; # a code, and a yadda yadda ?

-- 
 ()  Yuval Kogman <nothingmuch@woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /me sushi-spin-kicks : neeyah!!!!!!!!!!!!!!!!!!!!



Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About