Odd word problem/TrivialCharacterStreamSupportForJ: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "J lacks a character stream implementation, so this is a minimal sketch of "get a character" and "put a character" code. Note that the =. definitions provided here are for illust...")
 
mNo edit summary
Line 16: Line 16:
outch=: 3 :0
outch=: 3 :0
outstream=: outstream, y
outstream=: outstream, y
''
)</lang>
)</lang>

Revision as of 11:48, 7 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 the =. definitions provided here are for illustration purposes only (and, in fact, they will be discarded after loading the code from file), and are meant to be replaced by similar code at stream initialization time. Note that this implementation allows only one input stream and one output stream per locale.

<lang j>instream=. 'example text'

 last=. _1

 getch=: 3 :0
   last=: last+1
   last{instream
 )


outstream=.

 outch=: 3 :0
   outstream=: outstream, y
 )</lang>