RM=Raul Miller, JC=JC Coez RM> If I wanted to make this work, I'd have to figure out how to read and RM> write lines.
JC> When you will have some time to solve that please let me know. Here is the first draft of a Read (Evaluate) Print Loop for J. It's pure J; there are no host calls. It's only half baked at the moment, and requires more architecure and polish, but it contains the seed of a useful idea. And, if your needs are simple enough, it can probably solve your current dilemma. http://www.jsoftware.com/svn/DanBron/trunk/general/r_pl.ijs As a bonus, it provides an answer to the FAQ "In the J session manager, how can my script prompt the user for input?" (This question has been raised repeatedly lately, but I can't find a reference. Here's an older one: http://www.jsoftware.com/pipermail/general/2001-September/007603.html .) Here's a synopsis. There are two useful adverbs defined by the script: r_pl and r_plx . They're the same except the latter exits J with 2!:55 at the end (useful for console apps). The name stands for Read (Evaluate) Print Loop (with an underscore for Evaluate because you're supposed to fill in that blank). And that's exactly what it does. It reads one line from stdin or the session manager, passes it to your evalutor, which should return rc;rt where rc is the return code and rt is the text to be printed. The return code is either _ which means "Continue processing" (i.e. read the next line), 0 which means "completed succesfully" (i.e. don't read any more lines) or something else, which means "terminated due to error" (again, no more lines will be read). In r_plx under jconsole, the return code becomes the argument to 2!:55 which itself becomes the return code of your process. If your process terminates with 0, the last line will be printed to stdout, else it'll be printed to stderr. (The code doesn't yet support printing to stderr inline [i.e. raising non-fatal errors and continuing the loop]), but if there's interest I'll develop the script a bit more. One major issue is I don't have access to a (non-Cygwin) linux testing environment. Here is an example of use under the J Session Manager on Windows. See the example script http://www.jsoftware.com/svn/DanBron/trunk/general/r_pl-example.ijs : load '~user\util\general\r_pl-example.ijs' Please; reverse my lines! !senil ym esrever ;esaelP When you want to quit, use the J convention noitnevnoc J eht esu ,tiuq ot tnaw uoy nehW of terminating with a lone right paren nerap thgir enol a htiw gnitanimret fo ) ) +-+-+ |0|)| +-+-+ Here is an example of use under jconsole as a stdin/stdout process (also under Windows): jconsole -js "(_ ,&<;:) r_plx ''[require '~user\util\general\r_pl.ijs'" this is J tokenization +----+--+-+------------+ |this|is|J|tokenization| +----+--+-+------------+ +/ i. 5 1 +-+-+--+---+ |+|/|i.|5 1| +-+-+--+---+ (etc), etc} etc +-+---+-+-+---+-+---+ |(|etc|)|,|etc|}|etc| +-+---+-+-+---+-+---+ the Eval function has a constant return code of _ +---+----+--------+---+-+--------+------+----+--+-+ |the|Eval|function|has|a|constant|return|code|of|_| +---+----+--------+---+-+--------+------+----+--+-+ so the only way to terminate is with an error +--+---+----+---+--+---------+--+----+--+-----+ |so|the|only|way|to|terminate|is|with|an|error| +--+---+----+---+--+---------+--+----+--+-----+ like a unpaired ' |open quote | like a unpaired ' | ^ | 2!:55>{. (_,&<;:)R_PL'' I hope this helps. -Dan ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
