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
there is no requirement that definitions have to come before the parts of the script that call the definitions [...]
while showing these scripts as examples of how definition order does not matter:
defgreet [name] {
["hello"$name]
}
greet"world"
greet"world"defgreet [name] {
["hello"$name]
}
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"] and nothing respectively.
However, this confused me initially and I would expect this to trip up some other new users as well.
and then moving the definition of greet-world to the top is probably the best example I can think of right now.
Alternatively, the different output could be explained in a small note. I'm not even sure sure if the book explains the last expression of a script being printed up to that point. It's definitely explained in a note for functions but I don't remember reading that the same applies for scripts. I wouldn't rule out that I simply missed that part, though.
The text was updated successfully, but these errors were encountered:
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.
However, the statement could of course not be true in general. I can't really tell as I'm 2 days into Nushell.
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.
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: