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
I believe that what you've discovered is how it's supposed to work.
$my_record|updateage { $in+1 }
The use of update age ... here isn't supposed to update the variable$my_record. It takes the output of $my_record, updates the output as directed, and reports that output. If you want to store that new output in a variable, you have to tell nushell since variables declared with let are immutable.
Also, when you try to update it like this $my_record = $my_record | update age { $in + 1 }, you're actually not updating the original $my_record, you're shadowing it with a new variable of the same name.
The only mutable variables that nushell has right now is mut variables.
I believe this has tripped others up before too. Perhaps we should add in a clarifying comment that update is not meant to mutate the original record, it's meant to create a new updated copy.
After having played around with variables it does make sense but not initially when it's presented at the start of the page, meaning it's confusing for a beginner or someone who touched SQL in the past.
Affected pages:
Problem:
Following example gives the impression that
$my_record
should get mutated into31
(which makes sense when having worked with SQL queries in the past):However, if you inspect it with
print
you'll see that wasn't the case:$ nu script.nu
What works
This is merely a unbiased observation from a beginner, please feel free to close this if you don't agree with my assessment 🙂
The text was updated successfully, but these errors were encountered: