Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

command line input for J

Tags:

input

j

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.

like image 281
Zhe Hu Avatar asked Feb 28 '26 03:02

Zhe Hu


1 Answers

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.

like image 73
Eelvex Avatar answered Mar 03 '26 22:03

Eelvex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!