On this page of the J documentation, there is a command to print values to stdout and the display: http://www.jsoftware.com/help/dictionary/dx001.htm
Specifically: x 1!:2 y Write.
This seems to suggest it would be possible to call this with the value of y of 2 for screen output, and 4 for stdout, like so:
'123' 1!:2 2
However, when I run this code, I only get the error: "rank error". So my question is, how to use the 1!:2 primitive to print out data values to the screen or stdout?
I notice from another example in the verb echo, this appears to work, but why would I need to bond the 4 to the 1!:2 in order to make it work?
echo '123' (1!:2&4) '123'
Thanks!
J reads from right to left so it is treating the right argument of !: as 2 2 which is why you are getting the rank error.
'123' 1!:2 2
|rank error
| '123'1 !:2 2
You can fix this by isolating the 2 that you would like to be the right argument of the 1!:2 foreign conjunction.
'123' 1!:2 (2) NB. Parenthesis to isolate the argument
123
123
'123' 1!:2 [ 2 NB. verb [ sends the 2 through to 1!:2
123
123
'123' (1!:2) 2 NB. or you can isolate the conjunction
123
123
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With