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
It is currently impossible to update/insert/upsert a nested path from a variable:
let p = 'ls.use_ls_colors'
$env.config | upsert $p false
Nushell treats $p as a string and instead of setting $env.config.ls.use_ls_colors, it ads a new entry $env.config.'ls.use_ls_colors'. This is also a bug because you shouldn't be allowed to have . as a column name.
Describe the solution you'd like
IMO, the first parameter to update/insert/upsert (and possibly other relevant commands) should auto-convert the string into a nested cell paths.
Another option would be to add into cell-path command that would do the same, and you'd have to call upsert ($p | into cell-path) false.
The options are not mutually exclusive. Either way, the bug that . can appear as a column name should be fixed.
I really don't like automatically casting string to cell path (regardless of whether that's easy or not). Don't other programming languages deal with this by just having computed indexing? In Javascript you'd do foo[bar][baz]. To me, in Nushell you ought to be able to do stuff like (ls).($rownumber).name or upsert ($p).($q) false. Obviously this doesn't allow storing a full path inside a string like in your example, but that doesn't really inconvenience other languages that much.
Also, allowing . in column names is by no means a bug: you need to be able to create stuff like {filename.txt: 200b, a.out: 0b} in the language. ls | group-by name would immediately stop working if you forbade it.
All such issues are basically a sub-issue of #7033.
It's about Nu not interpreting interpretable stuff & just making it a string.
This limits programmability & automatisation a lot.
The day Nu will stop making strings out of legitimate, programmatic arguments, will be the day the functionality & programmability & therefore usefulness of Nu will dramatically increase.
My two cents, nu is both programming language + shell, so things gets interesting whenever this kind of feature requesting coming in. For this particular one, I feel we want to should support the auto-conversion, which does not have to change the parser dramatically.
Regards to Into cellpath command, what else Vaule type could be considered as IntoCellPath convertible?
I'd like to continue the discussion prior to your comments
I think this is a great idea but IMO it should be more robust. I can see a couple of points where the command would fail:
Quoted cell path members: "foo.'filename.txt'"
Cell paths with integers: "foo.0.b"
I keep thinking we shouldn't add new logic handling these cases because that would be just duplicating the logic that's already in the parser. What I would try:
Create a new working set and use the lexer to correctly split the input string, same as here.
Use parse_cell_path() on the stream of tokens to get the cell path expression
Create Value::CellPath from the expression.
Stuff like that is generally not safe, but I think this should OK because the CellPath and PathMember structs do not reference anything new added to the newly created working set (which will be thrown away). They only point at spans which are already present in the old working set. It would be a problem if we added subexpressions to cell paths, like foo.(let x = 'bar'; $x).
If I get this understood correctly, you would like to see and try re-tokenizing during into cellpath's run function. Nu has parsing and eval phases running separately, they should not be intervening with each other? Or I just misunderstood your comment?
Activity
webbedspace commentedon Dec 4, 2022
I really don't like automatically casting string to cell path (regardless of whether that's easy or not). Don't other programming languages deal with this by just having computed indexing? In Javascript you'd do
foo[bar][baz]. To me, in Nushell you ought to be able to do stuff like(ls).($rownumber).nameorupsert ($p).($q) false. Obviously this doesn't allow storing a full path inside a string like in your example, but that doesn't really inconvenience other languages that much.Also, allowing
.in column names is by no means a bug: you need to be able to create stuff like{filename.txt: 200b, a.out: 0b}in the language.ls | group-by namewould immediately stop working if you forbade it.theAkito commentedon Dec 4, 2022
All such issues are basically a sub-issue of #7033.
It's about Nu not interpreting interpretable stuff & just making it a string.
This limits programmability & automatisation a lot.
The day Nu will stop making strings out of legitimate, programmatic arguments, will be the day the functionality & programmability & therefore usefulness of Nu will dramatically increase.
[-]Treat strings as cell paths more predictably[/-][+]Construct cell paths programmatically[/+]Kangaxx-0 commentedon Dec 7, 2022
My two cents, nu is both programming language + shell, so things gets interesting whenever this kind of feature requesting coming in. For this particular one, I feel we want to should support the auto-conversion, which does not have to change the parser dramatically.
Regards to
Into cellpathcommand, what elseVauletype could be considered asIntoCellPathconvertible?into cellpath command (#7417)
kubouch commentedon Dec 10, 2022
See also #7417 (comment)
Kangaxx-0 commentedon Dec 11, 2022
I'd like to continue the discussion prior to your comments
If I get this understood correctly, you would like to see and try re-tokenizing during
into cellpath'srunfunction. Nu hasparsingandevalphases running separately, they should not be intervening with each other? Or I just misunderstood your comment?fdncred commentedon Mar 10, 2024
closed because we have
into cell-pathnow #11322