문제

I am trying to read command line input following this link (http://www.jsoftware.com/help/user/hashbang.htm)

0".>,.2}.ARGV

I can understand that 2}.ARGV drops the "jconsole" and the program name part.

0". turns string into numbers

why do we need ,.

which seems to add an extra rank to the input parameters unnecessarily, in case

'a b c d' =: 0".>,.2}.ARGV
 $a
 1

Why not just

'a b c d' =: 0".> 2}.ARGV
$a

Another cautionary note:

'a' =: 0".> 2}.ARGV
$a
1

So if you only have one argument passed in, 'a' becomes a list with rank 1, rather than one element of the input list.

도움이 되었습니까?

해결책

The difference is that without the ,., the result is not always a list of "number"ed (".) items, one for each argument. Ravelling guarantees that 0". will apply to each argument separately.

For example, if your ARGV is a list of characters:

]in =: 2 }. ARGV
┌─┬─┬─┬─┐
│1│2│3│4│
└─┴─┴─┴─┘
> ,. in
1
2
3
4

but

> in
1234

so

0". > ,. in
1 2 3 4

but

0". > in
1234

Other ways to apply 0". to each argument separately include (0". >)"0 in and > 0". &.> in. From those three, the one using the ravel is the most efficient.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top