uiua-lang / uiua

A stack-based array programming language
https://www.uiua.org
MIT License
1.63k stars 117 forks source link

Writing streams to stdout/stderr? #168

Closed artemisSystem closed 1 year ago

artemisSystem commented 1 year ago

From what i can tell, it doesn't seem possible to write directly to stdout. I can use &w to write to /dev/stdout, but if i try to pipe the output (uiua run file.uiua | something_else), i get a permission denied error:

❯ uiua run image.uiua | cat
Error: Permission denied (os error 13)
   ╭─[image.uiua:1:12]
 1 │ &cl &w ⊙.∶ &fo "/dev/stdout" &ime "png" ↯100_100 ÷1000⇡1000
   │            ───  
───╯

Would you consider adding functions to read from stdin, and writing to stdout/stderr?

kaikalii commented 1 year ago

This is odd. The interpreter uses Rust's File::open when you call &fo, so I guess that's the behavior it gives? Regardless, The handles 0, 1, and 2 are reserved, so reading from/writing to them should get you the behavior you want.

artemisSystem commented 1 year ago

ah, i didn't try that directly, will try that later