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

Introduce a :*@foo slurpy named argument syntax #452

Open
lizmat opened this issue Oct 27, 2024 · 4 comments
Open

Introduce a :*@foo slurpy named argument syntax #452

lizmat opened this issue Oct 27, 2024 · 4 comments
Labels
language Changes to the Raku Programming Language

Comments

@lizmat
Copy link
Collaborator

lizmat commented Oct 27, 2024

Inspired by rakudo/rakudo#2797

This would allow:

% raku -e 'sub foo(:@bar) { dd @bar }; foo :bar<a>' 
Type check failed in binding to parameter '@bar'; expected Positional but got Str ("a")
  in sub foo at -e line 1

to just work like:

% raku -e 'sub foo(:@bar) { dd @bar }; foo :bar<a b>'
("a", "b")

The syntax is currently a compilation error:

% raku -e 'sub foo(:*@bar) { dd @bar }; foo :bar<a>' 
===SORRY!=== Error while compiling -e
Missing block
at -e:1
------> sub foo(:⏏*@bar) { dd @bar }; foo :bar<a>

Disadvantages: apart from the grammar work, this would also need quite a bit of work in the binder. And the user would need to know to specify :*@foo instead of :@foo.

Advantages: would be generally useful, and would allow the "adapt the Capture hack" in MAIN handling to be removed.

@Leont
Copy link

Leont commented Nov 1, 2024

How would this interact with typed variables? Would that just not be allowed?

@lizmat
Copy link
Collaborator Author

lizmat commented Nov 18, 2024

Adding type checking to slurpy arrays in general should be doable within the new Raku grammar and RakuAST.

But if that wouldn't happen, then yes the same limitation would apply, I'd say.

@landyacht
Copy link

Would there also be **- and +-type slurpies of this sort, e.g. for controlling behavior for parameters like :foo(@bar, 'baz') or :foo(@bar, @baz)?

Ref. https://docs.raku.org/language/signatures#Types_of_slurpy_array_parameters

@codesections
Copy link
Contributor

I'm don't have a well-thought-out view on whether this change is worthwhile, but I'll mention that

sub foo(:@bar) { dd @bar }; 
foo :bar["a"];

already works, which slightly reduces the use-case for this new syntax outside of MAIN/cli argument parsing. (Might still be worth adding, though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes to the Raku Programming Language
Projects
None yet
Development

No branches or pull requests

4 participants