-
Notifications
You must be signed in to change notification settings - Fork 419
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
Confusing example on script definition order #1163
Comments
The statement, "there is no requirement that definitions have to come before the parts of the script that call the definitions" used to be true but I've seen several instances where order matters. I'm not sure if that means the docs are wrong or if there's a bug in nushell. |
I believe the statement holds for the given example as I would expect the script to error out otherwise. I should add that when I originally encountered this behavior, I also looked for duplicates in the main repository and found this recent issue that was indeed a bug but has been fixed since. |
This isn't an order thing, but rather we no longer automatically print output of every line. def greet [name] {
["hello" $name]
}
greet "world" Should now be: def greet [name] {
print ["hello" $name]
}
greet "world" And similar with the second example. |
Issue
I'm currently reading the book which claims that
while showing these scripts as examples of how definition order does not matter:
This choice of examples is a bit unfortunate in my opinion as, when running both scripts, they have different output.
My understanding is that this is caused by the last expression in a script being printed which evaluates to
["hello" "world"]
andnothing
respectively.However, this confused me initially and I would expect this to trip up some other new users as well.
Possible improvements
or
would result in the same output when moving the command invocation line around but might raise other questions.
and then moving the definition of
greet-world
to the top is probably the best example I can think of right now.The text was updated successfully, but these errors were encountered: