+/ ( [: ".;._1 ','&,);._1 LF , '1,2,3,4,5'
1 2 3 4 5
NB. because
   $( [: ".;._1 ','&,);._1 LF , '1,2,3,4,5'
1 5
NB. You probably want something like:
   +/, ([:".;._1 ','&,);._1 LF , '1,2,3,4,5'
15

If the numbers had still been character, you would have gotten an error as
"+" is not defined for characters.

The real question is why you are cutting on LF when there aren't any in your
string: are you planning to use this expression on strings with embedded
LFs?  Like this:

   +/ ( [: ".;._1 ','&,);._1 LF , '1,2,3,4,5',LF,'10 20 30 40 50'
11 22 33 44 55

When reading characters from file to convert them to numbers, I find it
handy to use cut with a "_2" qualifier to cut on the last element, e.g.

   ('1,2,3,4,5',LF,'10 20 30 40 50',LF) fwrite 'file.txt'
25
   <;._2 fread 'file.txt'
+---------+--------------+
|1,2,3,4,5|10 20 30 40 50|
+---------+--------------+
NB. leading to
   ([:+/".) &> <;._2 fread 'file.txt'
15 150


On Thu, Feb 12, 2009 at 8:37 AM, Steven Taylor <[email protected]> wrote:

>   +/ 1 2 3 4 5
> 15
>
>   +/ ( [: ".;._1 ','&,);._1 LF , '1,2,3,4,5'
> 1 2 3 4 5
>
> Are the numbers still in string format?
>
> Reason: J familiarisation and would like to run some tests.
>
> thanks
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to