Skip to content

1 + 1 should work #574

Closed
Closed

Description

@wycats

Raw expressions should work as commands

Activity

  1. self-assigned this
    on Sep 2, 2019
  2. added
    polish
    on Sep 2, 2019
  3. wycats commented on Sep 2, 2019

    @wycats
    ContributorAuthor

    This would also make:

    $ get_some_value | 1 + $it
    

    work

  4. casey commented on Sep 2, 2019

    @casey

    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.

  5. obust commented on Sep 2, 2019

    @obust

    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.

  6. leroycep commented on Sep 3, 2019

    @leroycep

    I like how the elvish shell handled this: it made + and - a command. For example:

    ~> * (+ 40 2) 10
    ▶ 420
    

    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!

  7. rrichardson commented on Sep 4, 2019

    @rrichardson
    Contributor

    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>

    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

    ps | edit cpu = :cpu / 12
    
  8. rrichardson commented on Sep 4, 2019

    @rrichardson
    Contributor

    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.

  9. rrichardson commented on Sep 4, 2019

    @rrichardson
    Contributor

    As a root level function, it still seems intuitive:

    /home/me> =  336 / 8 
     42 
    

    And, of course, once we introduce environment variables interaction, I'm sure whatever variable syntax should work there as well.

    /home/me>  =  $SHELL ++ " is the best shell!" 
    nu is the best shell!
    

    (or whatever the string concationation operator is )

  10. sophiajt commented on Apr 27, 2020

    @sophiajt
    Contributor

    This is fixed as of 0.13.0, using the syntax @rrichardson suggests

  11. added a commit that references this issue on Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

polish

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions