At 00:38  -0400 2007/05/21, Terrence Brannon wrote:
On 5/21/07, Joey K Tuttle <[EMAIL PROTECTED]> wrote:

$ cat cs.ijs
echo +/ 0&". ;._2 stdin''

can you explain this to me? I know a good amount of it:

0&". you are creating a monadic verb which will convert its argument to a number
+/     you are summing a list of numbers
;. _2 stdin ''  NB. has me confused
 -- is '' 2 single quotes or a single double quote
 -- i dont see how ;. _2 stdin plays together
 -- I dont understand ;. yet

cut (;.) is very powerful/useful, I recommend study of
the dictionary page. My use of it (;._2) applies the
left verb (0&". - which, as you say, converts a string
to a number with 0 as the replacement for ill-formed
numbers) to each line of the file excluding the line
ends (the single character LF) in Linux/Unix systems.
That does indeed return a vector of 1000 numbers from
the proscribed test file which is received via stdin''
(that is an empty right argument - 2 single 's) +/
is summation (+ inserted between each atom of the
vector) echo sends a result back out to the console
that is stdout (so it can be further piped if wanted).

Maybe some parentheses will help show associations -

  echo +/ (0&". ;._2) stdin ''

Which I suppose you could "read in English" as:

  echo the summation of all the numbers derived from
    each line of the file received from standard input

Experimenting is always a good idea, to clarify what
happens - you could try something like:

$ cat bcs.ijs
echo 0&". ;._2 stdin ''

$ head sumcol-input.txt | ja bcs.ijs
276 498 _981 770 _401 702 966 950 _853 _53

$ tail sumcol-input.txt | ja bcs.ijs
_33 _965 752 474 _731 758 _573 4 38 264

That is, the first and last 10 numbers in the file.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to