Re: RFC 57 (v1) Subroutine prototypes and parameters
[email protected] (Piers Cawley) 07 Aug 2000 16:47:00 +0100
| Newsgroups | perl.perl6.language.subs |
|---|---|
| Message-ID | <[email protected]> |
Piers Cawley <[email protected]> writes: > Perl6 RFC Librarian <[email protected]> writes: > > This has a dangerous and unpredictable side-effect which we would rather > > avoid. So the third and preferred candidate is: > > > > foo(x = 10, y = 20); > > > > In Perl 5 this is a syntax error raising a 'Bareword "x" not > > allowed...' error message. This is a Good Thing because it implies > > there aren't (m)any existing scripts that are currently using this > > construct. > > > sub x : lvalue { $x } > sub y : lvalue { $y } > > foo(x = 10, y = 20); > > However, I note that: > > foo(x:10, y:20) > > throws a syntax error, as does: > > foo($x:10, $y:20) > > Hey! So does: > > foo($x := 10, $y := 20) > > But that looks painful. > > I also note that given > > sub ($x, $y, $z) { #stuff > } > > It might be nice if: > > $curried_foo = foo(x:10, y:20); > > returned an appropriately curried function... But Damian's already > doing curries elsewhere... Oops, just realised, that won't fit in with the possibility of the defaulted values elsewhere. Maybe we could have: $curried_foo = foo(x := 10, y := 20) do the currying, with a plain old colon being a named parameter type call.