Improve documentation on "magic" variables
I've noticed here and there that it is possible to directly refer to a parameter in a command without declaring it in a block. E.g.
echo $scores | where $it > 7
[1, 2, 3] | $in.2
It appeals to me because I find that the declaration part with the pipes is a little annoying to type. But I can't find any documentation on when and where it might be used.
yup, documentation is lacking. i don't use either $it or $in very much. but i know these
ls | $in.2
ls | $in.size
i don't use either $it or $in very much.
The concept reminds me of the $_ variable in perl and the _ in purescript (where _.name is a function x -> x.name).
In concept I don't like it very much either when it is not super clear where a variable comes from. But when it saves a lot of typing than that improves QoL a lot, since shell commands are write once read never most of the time.
The block notation in nushell strikes me a bit as odd. I haven't seen another languages using that { |$x| ...$x... } notation. Is there a specific reason why it is the way it is? I.e. where does it come from? Most of the time I see stuff like x => { x }.
Just a thought, would it perhaps be a good idea to have a single variable name that acts as shorthand for blocks with a single argument? I.e. { ...$_... } would expand to { |$_| ...$_...}. I guess there is a slight ambiguity with nested blocks, but one could use standard scoping rules for that.
Sorry for going slightly off-topic here. (Though on-topic in the sense that my last suggestion would be easier to document than having each command have it's own thing I think 😀 )
The concept reminds me of the $_ variable in perl
Strangely enough, powershell uses $_ as well as kind of a magic variable
The block notation in nushell strikes me a bit as odd
It was odd to me too. I think it's more of a functional programming language thing. It's pretty common in rust.
Just a thought, ...
I'm not sure that would fly. One of the big points to block parameter naming is to be able to next blocks and not consume or confuse variables inadvertently.