You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
closures and commands don't treat optional parameters the same #11287
letcode= {|x?| print ($x|default"i'm the default")}
do$code
see the following error
Error: nu::shell::variable_not_found
× Variable not found
╭─[entry #7:1:1]
1 │ let code = {|x?| print ($x | default "i'm the default")}
· ─┬
· ╰── variable not found
2 │ do $code
╰────
run
deffoo [x?] { print ($x|default"i'm the default") }
foo
see the expected output, i.e. i'm the default
Expected behavior
because closures and commands are so similar, i.e. closures are basically unnamed commands, i expected running
letcode= {|x?| print ($x|default"i'm the default")}
do$code
I encountered a problem with the spread operators that is so similar that I feel like the root cause is probably the same (so I decided to comment here rather than create a new issue). If I should create a new issue anyways just in case they don't have the same cause, and maybe just link to this issue, just let me know and I'll make it.
For closures and commands defined similarly to the above, except using spread operators rather than optional parameters
let code = {|...x|print ($x| default "i'm the default")}
def foo [...x] { print ($x| default "i'm the default") }
Given some parameters they both actually work the same and as expected
Activity
amtoine commentedon Dec 11, 2023
could reproduce with nightly
TWSiO commentedon Jan 20, 2024
I encountered a problem with the spread operators that is so similar that I feel like the root cause is probably the same (so I decided to comment here rather than create a new issue). If I should create a new issue anyways just in case they don't have the same cause, and maybe just link to this issue, just let me know and I'll make it.
For closures and commands defined similarly to the above, except using spread operators rather than optional parameters
Given some parameters they both actually work the same and as expected
However, if they are given no arguments, the command works as expected, but the closure gives the same error as above.
Not sure if that will be helpful for fixing the problem, but I thought I may as well add it.
Also, if it doesn't end up actually being the same cause, just let me know and I'll create a new issue.
`do` command: Make closure support default parameters and type checki…