Amelia Stein wrote:
 I want to write a script the equivalent
> of
> this C code in J:

I don't write many console interactive programs, but I do write
Unix filters, following the model in the J documentation.

One thing to bear in mind is that J is file-oriented rather than
stream-oriented, and for a first approximation, you have to be
prepared to read all of standard input.

The "main program" is designed as follows: write a verb f that
operates on a string representing all of standard input, and returns a
string representing all of standard output.  You then call it by

f &. stdin''

The example below expects a number as standard input.  It returns the
number incremented by 1.

file 1.ijs
----------
#!/home/john/j601/jconsole
scan=:".              NB. execute a string
trim=:}:              NB. remove trailing line feed
g=:>:                 NB. verb that operates on an integer
f=:g &.scan @: trim   NB. filter verb with string conversions
f &. stdin''          NB. "main program"
echo''                NB. append trailing newline
exit''

Execution

[EMAIL PROTECTED] tmp]$ ./1.ijs
10
11
[EMAIL PROTECTED] tmp]$

Best wishes,

John


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to