Odd word problem/TrivialCharacterStreamSupportForJ: Difference between revisions
Content added Content deleted
mNo edit summary |
(use a verb to initialize 'instream' and start with 'outstream' initialized) |
||
Line 1: | Line 1: | ||
[[../#J|J]] lacks a character stream implementation, so this is a minimal sketch of "get a character" and "put a character" code. |
[[../#J|J]] lacks a character stream implementation, so this is a minimal sketch of "get a character" and "put a character" code. |
||
Note that this implementation allows only one input stream and one output stream per locale. |
|||
<lang j> |
<lang j>begin_instream=: 3 :0 NB. |
||
instream=: y |
instream=: y |
||
last=: _1 |
last=: _1 |
||
outstream=: '' |
|||
) |
) |
||
instream=. 'example text' |
|||
last=. _1 |
|||
getch=: 3 :0 |
getch=: 3 :0 |
||
Line 19: | Line 14: | ||
outstream= |
outstream=: '' |
||
outch=: 3 :0 |
outch=: 3 :0 |
Revision as of 11:37, 8 November 2011
J lacks a character stream implementation, so this is a minimal sketch of "get a character" and "put a character" code.
Note that this implementation allows only one input stream and one output stream per locale.
<lang j>begin_instream=: 3 :0 NB.
instream=: y last=: _1
)
getch=: 3 :0 last=: last+1 last{instream )
outstream=:
outch=: 3 :0 outstream=: outstream, y )</lang>