-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Why do defaults on slurpies throw? #2440
Comments
It's a useful behaviour to have and I don't understand why it must throw instead: rakudo/rakudo#2440
I think the original reasoning is very simple: having *no* values for a slurpy is perfectly valid. One could re-consider that.
… On 28 Oct 2018, at 22:22, Zoffix Znet ***@***.***> wrote:
An optional % or @ sigiled param defaults to an empty list. You can also give it a default value:
<Zoffix__> m: m: -> @A? { dd @A }()
<camelia> rakudo-moar 266af373d: OUTPUT: «Array element = []»
<Zoffix__> m: m: -> @A = <default list> { dd @A }()
<camelia> rakudo-moar 266af373d: OUTPUT: «("default", "list")»
And while a slurpy param also defaults to an empty list, you cannot give it a default value:
<Zoffix__> m: m: -> ***@***.*** { dd @A }()
<camelia> rakudo-moar 266af373d: OUTPUT: «Array element = []»
<Zoffix__> m: m: -> ***@***.*** = <default list> { dd @A }()
<camelia> rakudo-moar 266af373d: OUTPUT: «===SORRY!=== Error while compiling <tmp>Cannot put default on slurpy parameter @Aat <tmp>:1------> m: -> ***@***.*** = <default list>⏏ { dd @A }() expecting any of: constraint infix stopper»
What's the reason for this limitation? It looks to be fairly useful when you want both the flattening of slurpies and some default values to work with.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Having no values for an optional |
I think it's because a slurpy is never "not given". A param, $@% can simply be not passed, but a slurpy will always be "passed". |
Not really, I'm not "passing" anything. The callsite to a routine with optional
Parallels with
There's no ambiguity to the decision of when a slurpy should be given its default value, other than possible implementation detail in rakudo. On language-level, the decision to block slurpy defaults make no sense to me. |
No arguments for a positional (with no default) is invalid. |
So what? |
As in, I don't see the relevance of mandatory parameters to slurpies. You'll still have a total valid slurpy with no arguments if defaults are allowed. In fact, the current behaviour can be explained with a paragidm where a slurpy always has a default value: an empty And the current propspec says that default value must not be configurable by the user, to which I ask: "why?" |
It's a useful behaviour to have and I don't understand why it must throw instead: rakudo/rakudo#2440
@zoffixznet for what it's worth, I think the counterargument could be put in a different light the following way: what can one do to make the slurpy an empty list, if no values were to trigger the default value, rather than the empty list? And this is where things start to escalate quickly... a missing value is reflected with an empty array for an optional I'm not sure if the same distinction could be preserved(/achieved in the first place) in any way for a slurpy. |
An optional
%
or@
sigiled param defaults to an empty list. You can also give it a default value:And while a slurpy param also defaults to an empty list, you cannot give it a default value:
What's the reason for this limitation? It looks to be fairly useful when you want both the flattening of slurpies and some default values to work with.
There was propspec codifying this behaviour in 6.d and I moved it to APPENDIXES at least for now: Raku/roast@f7d9be8ad9
The text was updated successfully, but these errors were encountered: