Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow named arguments to set positional parameters #105

Closed
p6rt opened this issue May 25, 2008 · 5 comments
Closed

allow named arguments to set positional parameters #105

p6rt opened this issue May 25, 2008 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 25, 2008

Migrated from rt.perl.org#54808 (status was 'resolved')

Searchable as RT54808$

@p6rt
Copy link
Author

p6rt commented May 25, 2008

From @diakopter

named argument key pair parsed as a Pair argument (incorrectly), and
vice versa (incorrectly), when called without parens

see http://dev.perl.org/perl6/doc/design/syn/S06.html#Named_arguments

13​:23​:15 <diakopter> rakudo​: sub foo($w=4){say $w.perl}; foo 'w' => 3;
  # $w is positional (a Pair); this is correct, I think.
13​:23​:17 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]
13​:20​:52 <diakopter> rakudo​: sub foo(%w){say %w.perl}; foo 'w' => 3;
# %w is positional (a Pair); this is correct, I think.
13​:20​:54 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]
13​:23​:33 <diakopter> rakudo​: sub foo($w=4){say $w.perl}; foo w => 3;
# $w is a positional parameter, but w is passed as a named argument,
so this should fail with "not enough (positional) arguments"
13​:23​:39 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]
13​:24​:18 <diakopter> rakudo​: sub foo(​:$w=4){say $w.perl}; foo w => 3;
# $w is a named parameter ($w should be 3), but produces a Pair
("​:w(3)")
13​:24​:19 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]

@p6rt
Copy link
Author

p6rt commented May 26, 2008

From @pmichaud

On Sun, May 25, 2008 at 11​:41​:45AM -0700, diakopter wrote​:

named argument key pair parsed as a Pair argument (incorrectly), and
vice versa (incorrectly), when called without parens

see http://dev.perl.org/perl6/doc/design/syn/S06.html#Named_arguments

13​:23​:15 <diakopter> rakudo​: sub foo($w=4){say $w.perl}; foo 'w' => 3;
# $w is positional (a Pair); this is correct, I think.
13​:23​:17 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]

Rakudo has this correct.

13​:20​:52 <diakopter> rakudo​: sub foo(%w){say %w.perl}; foo 'w' => 3;
# %w is positional (a Pair); this is correct, I think.
13​:20​:54 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]

Rakudo doesn't know how to coerce a Pair (or list of pairs)
into a hash yet.

13​:23​:33 <diakopter> rakudo​: sub foo($w=4){say $w.perl}; foo w => 3;
# $w is a positional parameter, but w is passed as a named argument,
so this should fail with "not enough (positional) arguments"
13​:23​:39 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]

This should output "3". Synopsis 6 allows positional parameters
to be supplied using named arguments​:

: Required parameters may optionally be declared with a trailing !,
: though that's already the default for positional parameters​:
:
: sub numcmp ($x!, $y!) { return $x <=> $y }
:
: The corresponding arguments are evaluated in item context and
: may be passed positionally or by name. To pass an argument by
: name, specify it as a pair​: parameter_name => argument_value.
:
: $comparison = numcmp(2,7);
: $comparison = numcmp(x=>2, y=>7);
: $comparison = numcmp(y=>7, x=>2);

Yes, Rakudo gets this one wrong as well, but that's because
we haven't implemented the ability to set positional parameters
by name yet. Doing that is likely going to involve some
fixes to Parrot's calling conventions -- see
http://groups.google.com/group/perl.perl6.internals/msg/7532b6c5f0784849 .

13​:24​:18 <diakopter> rakudo​: sub foo(​:$w=4){say $w.perl}; foo w => 3;
# $w is a named parameter ($w should be 3), but produces a Pair
("​:w(3)")
13​:24​:19 <?? exp_evalbot ??> OUTPUT[​:w(3)␤]

I suspect evalbot had an outdated version of Rakudo at the
time -- the trunk version gives the correct answer​:

  $ ./parrot perl6.pbc
  > sub foo(​:$w=4){say $w.perl}; foo w => 3;
  3

We need to either reject/close this ticket, or update the subject
line to reflect its true status (i.e., [todo]​: set positional parameters
using named arguments).

Pm

@p6rt
Copy link
Author

p6rt commented May 26, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 20, 2009

From @moritz

Works now after the resig2 merge, jnthn++. Also unfudged a lot of
related tests.

@p6rt
Copy link
Author

p6rt commented Oct 20, 2009

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Oct 20, 2009
@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant