nushell icon indicating copy to clipboard operation
nushell copied to clipboard

`print` inside `each` or `for` blocks doesn't work if the pipeline puts a new value after the `each` or `for`

Open webbedspace opened this issue 2 years ago • 3 comments

Describe the bug

This is hard to explain, so please consult the examples below.

How to reproduce

〉[1 2 3] | do { print $in } | print 'Done'
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
╰───┴───╯
Done
〉[1 2 3] | each { print $in } | print 'Done'
Done
〉[1 2 3] | for i in $in { print $i } | print 'Done'
Done
〉[1 2 3] | each { print $in }
1
2
3
〉[1 2 3] | each { print $in } | 25
25

As you can see the print $in commands (EDIT: I mean 2nd, 5th and 3rd examples) don't work because the pipeline of the each or for pipes the block's result into print 'Done' or 25. do does not seem to have this problem, however. Thus, I suspect the issue lies with how the loops iterate over single values of the input list.

Expected behavior

I expect the print statements to work correctly.

Screenshots

No response

Configuration

key value
version 0.70.0
branch
commit_hash 9ef65dcd692b502d7476b1787247fae8638c2f0c
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.64.0 (a55dd71d5 2022-09-19)
rust_channel stable-x86_64-pc-windows-msvc
cargo_version cargo 1.64.0 (387270bc7 2022-09-16)
pkg_version 0.70.0
build_time 2022-10-18 18:55:02 +00:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

No response

webbedspace avatar Nov 01 '22 12:11 webbedspace

And when :

> [1 2 3] | do { each { print $in } } | print 'Done'
Done

Interesting

Decodetalkers avatar Nov 01 '22 14:11 Decodetalkers

I expect the print statements to work correctly.

I'm not sure which is "correctly" from your perspective. Do you mean this?

〉[1 2 3] | do { print $in } | print 'Done'
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
╰───┴───╯

Do you mean this?

〉[1 2 3] | each { print $in }
1
2
3

Are both of those correct? or wrong? or is "correct" different for each case? or does is the first one right if it prints 'Done'?

fdncred avatar Nov 01 '22 17:11 fdncred

Sorry, I misworded that message. I meant all of these:

〉[1 2 3] | each { print $in } | print 'Done'
Done
〉[1 2 3] | for i in $in { print $i } | print 'Done'
Done
〉[1 2 3] | each { print $in } | 25
25

webbedspace avatar Nov 01 '22 18:11 webbedspace