J言語メモ

#基礎編

##hello, world

https://tio.run/#j

```ex.ijs
echo 'hello, world'
```

##記号・ワード

https://code.jsoftware.com/wiki/NuVoc

https://code.jsoftware.com/wiki/Standard_Library/Overview

## Comment

```ex.ijs
NB. comment
0 : 0
hoge =. monad define
	y * y
)
```

ラテン語：Nota Bene、英語：note well、注釈の意

https://code.jsoftware.com/wiki/Vocabulary/ncapbcapdot

https://code.jsoftware.com/wiki/Standard_Library/stdlib#Note

##数値

```ex.ijs
echo 2b1101
echo 16bcafe
echo toupper hfd 51966
echo ! 30
echo ! 30x
echo 1r3 + 1r4
echo | _5 5 3j4
echo 24 60 60 #: 10000
echo 24 60 60 #. 2 46 40
```

```
13
51966
CAFE
2.65253e32
265252859812191058636308480000000
7r12
5 5 5
2 46 40
10000
```

https://qiita.com/unsigned-wrong-wrong-int/items/96ed987360617667c29b

##文字

```ex.ijs
echo a. i. CRLF
echo a. i. 'ABC'
echo 65 66 67 { a.
```

```
13 10
65 66 67
ABC
```

##代入

```ex.ijs
hoge =. monad define
    c =. y * a
    d =: c + 1
)
a =: 2
b =. 3
echo hoge 4
echo d
```

```
9
9
```

=: グローバル
=. ローカル

##定義

tacit、暗黙

```ex.ijs
not =. -.
or =. +.
ne =. ~:
echo 5 OR 3
echo not 2 1 0 _1 _2
echo 0 1 0 1 or 0 0 1 1
echo 0 1 2 3 ne 0
```

```
7
_1 0 1 2 3
0 1 1 1
0 1 1 1
```

Explicit definition

```ex.ijs
hoge =. monad define
	y * y
)
piyo =. dyad define
	x % y
)
echo hoge 4
echo 2 piyo 3
```

```
16
0.666667
```

https://code.jsoftware.com/wiki/Guides/Defining_Verbs

```ex.ijs
verb define 'hello, world'
	echo y
)
```

```
hello, world
```

## リスト

```ex.ijs
echo 1 2 3 , 4 5 6
echo 'abc' , 'def'
```

```
1 2 3 4 5 6
abcdef
```

## テーブル

```ex.ijs
echo +/ 1 2 3 4
echo 1 2 3 */ 1 2 3 4
echo ((i: 2) * 0j1) +/ (i: 3)
```

```
10
1 2 3  4
2 4 6  8
3 6 9 12
_3j_2 _2j_2 _1j_2 0j_2 1j_2 2j_2 3j_2
_3j_1 _2j_1 _1j_1 0j_1 1j_1 2j_1 3j_1
   _3    _2    _1    0    1    2    3
 _3j1  _2j1  _1j1  0j1  1j1  2j1  3j1
 _3j2  _2j2  _1j2  0j2  1j2  2j2  3j2
```

##4次元

```ex.ijs
echo 2 2 2 3 $ i. 100
```

```
 0  1  2
 3  4  5

 6  7  8
 9 10 11


12 13 14
15 16 17

18 19 20
21 22 23
```

##Dynamic Power

```ex.ijs
hello =. verb define
	echo 'hello, world'
)
hello ^:] 3
```

```
hello, world
hello, world
hello, world
```

https://code.jsoftware.com/wiki/Vocabulary/hatco

#応用編

##J Version

```ex.ijs
echo 9!:14 ''
```

```
j806/j64/linux/release/commercial/www.jsoftware.com/2017-11-06T09:54:01
```

https://code.jsoftware.com/wiki/Vocabulary/bangco

##出力

```ex.ijs
echo 'hello, echo'
sminfo 'hello, sminfo'
smoutput 'hello, smoutput'
tmoutput 'hello, tmoutput' , LF
```

```
hello, echo
hello, sminfo
hello, smoutput
hello, tmoutput
```

##printf

```ex.ijs
require 'format/printf'
'%j: %j' printf 'abc' ; 1 2 3
a =. '%X' sprintf 16bcafe
echo a
qprintf 'a '
```

```
abc: 1 2 3
CAFE
a=CAFE
```

https://code.jsoftware.com/wiki/Vocabulary/Printf

##datatype

```ex.ijs
echo datatype 1
echo datatype 2
echo datatype 0.5
echo datatype 1x
echo datatype 1r2
echo datatype 0j1
echo datatype 'a'
echo datatype <0
```

```
boolean
integer
floating
extended
rational
complex
literal
boxed
```

##分類

```ex.ijs
echo noun
echo adverb
echo conjunction
echo verb
echo monad
echo dyad
```

```
0
1
2
3
3
4
```

0 noun 名詞
1 adverb 副詞
2 conjunction 接続詞
3 verb 動詞
3 monad (monadic) 単項
4 dyad (dyadic) 二項

#参考

https://qiita.com/unsigned-wrong-wrong-int/items/e15a87999cedfc6b9ced

https://github.com/Stosstruppe/asciiart/tree/master/J

https://www.jsoftware.com/

https://code.jsoftware.com/

https://code.jsoftware.com/wiki/APL2JPhraseBook