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
Parsing here is space sensitive. Only if surrounded by spaces will + be interpreted as the add operator. The same rule applies to -. This let's us have kebab-case command names without nu erroring on substraction: from-csv, to-csv, etc.
Firstly, being able to do one-off calculations is great, but calculated fields is a big differentiator. To work, though, we'd need to be able to reference columns within the expressions.
We need something to indicate the start of an expression. We need to be able to reference a column for any given row (and maybe even adjacent rows in the future)
Meanwhile, nushell has multiple shells that are rendering tables from multiple data sources.. .
If you blur your eyes a bit, the whole thing looks a bit like a spreadsheet. So.. my syntax proposal should not be surprising.
Indicate the beginning of an expression or "formula" with =
Reference the column name either by :<col-number> or :<name>
ps | add normalized-cpu = :cpu / 12`
this is assuming that the syntax for adding a column is add <column name> <value to put in the column>
so populating a field with a constant value would simply be:
ps | add boring static_value
so the = at the beginning of a value would indicate that the result would need to be calculated.
I would assume that editing a column should require the same expression
I guess this would mean that we could consider = a function, and it would expect standard mathematical functions to follow it.
It would optionally have a list of named values passed to it as a parameter, in case this expression was executed as part of a table filter.
Activity
wycats commentedon Sep 2, 2019
This would also make:
work
casey commentedon Sep 2, 2019
Would this potentially make nu attempt to parse some input intended to be commands as expressions?
I'm thinking of things like
cargo +nightly build.obust commentedon Sep 2, 2019
Parsing here is space sensitive. Only if surrounded by spaces will
+be interpreted as the add operator. The same rule applies to-. This let's us have kebab-case command names without nu erroring on substraction:from-csv,to-csv, etc.leroycep commentedon Sep 3, 2019
I like how the elvish shell handled this: it made
+and-a command. For example:This also has the benefit of making them "regular" command line programs; just pass in some arguments and you're good.
Also, thumbs up on arithmetic in the terminal. It drives me crazy that it's so difficult to add two numbers together in most shells!
rrichardson commentedon Sep 4, 2019
Ok. Here is my proposal:
Firstly, being able to do one-off calculations is great, but calculated fields is a big differentiator. To work, though, we'd need to be able to reference columns within the expressions.
We need something to indicate the start of an expression. We need to be able to reference a column for any given row (and maybe even adjacent rows in the future)
Meanwhile, nushell has multiple shells that are rendering tables from multiple data sources.. .
If you blur your eyes a bit, the whole thing looks a bit like a spreadsheet. So.. my syntax proposal should not be surprising.
Indicate the beginning of an expression or "formula" with
=Reference the column name either by
:<col-number>or:<name>this is assuming that the syntax for adding a column is
add <column name> <value to put in the column>so populating a field with a constant value would simply be:
so the
=at the beginning of a value would indicate that the result would need to be calculated.I would assume that editing a column should require the same expression
rrichardson commentedon Sep 4, 2019
I guess this would mean that we could consider
=a function, and it would expect standard mathematical functions to follow it.It would optionally have a list of named values passed to it as a parameter, in case this expression was executed as part of a table filter.
rrichardson commentedon Sep 4, 2019
As a root level function, it still seems intuitive:
And, of course, once we introduce environment variables interaction, I'm sure whatever variable syntax should work there as well.
(or whatever the string concationation operator is )
sophiajt commentedon Apr 27, 2020
This is fixed as of 0.13.0, using the syntax @rrichardson suggests
add 68 blog (nushell#574)