💾 Archived View for blitter.com › apl-books › apl.maxhost.org › j-programming-notes.txt captured on 2022-07-16 at 17:21:33.
View Raw
More Information
-=-=-=-=-=-=-
install'gtkide'
http://www.jsoftware.com/help/learning/02.htm
ctrl-d exit
cursor up/down scroll through history
; the verb link
=. local assignment
=: global assignment
'hello world' prints hello world
text =. 'hello world'
store string in text
+/1 2 3 sum the numbers 1 2 3
- /1 2 3 multiply the numbers 1 2 3
4%2 divide 4 by 2
4*2 multiply 4 y 2
5 + 10 20 30 add 5 to 10 20 30
avg=: +/ % # program to calculate average, e.g. avg 1 2 3 4 5 returns 3
m=: ?. 4 5 $ 50
create a matrix 4x5 with random numbers
<1 0 0 1 0 boxed data
6!:0 '' current time
6!:1 '' seconds since the start of session
v =. green apple dog
set array v to green apple dog
a =. 1 2 3 4 set array a to 1 2 3 4
a+1 returns 2 3 4 5
a%2 returns 0.5 1 1.5 2
;: '2 + 3'
load 'convert'
toupper 'testing 1 2 3'
+/i.11 sum the numbers 0 to 10
sum=: +/ assign sum to sum
b =. 1 2 3 4 5
sum b
#b return number of elements of b (
# also returns the number of characters in a string
t =. 'text'
~. t return unique characters of t
sort t returns the characters of t sorted
i.10 return numbers 0 to 9
2^3 returns 2 to the power of 3
? 20#100 generate 20 random numbers from 0 to 99
0! zero factorial returns 1
!x: i.5 returns the factorials from 0 to 4 (e.g. 1 1 2 6 24)
scores =: 45 67 89 12 34 55 77 90
/:~scores sorts scores
6 +. 10 returns greatest common divisor between 6 and 10
v=: ?. 10 $ 10 generate 10 random numbers from 0 to 9
- : 4 calculate square of 4
- : 1 2 3 4 calculate squares of 1 through 4
2 | 7 returns 2 modulo 7 (e.g. 1)
1 + (u =: 99) assign 99 to u and add 1
table =: 2 3 $ 5 6 7 8 9 10
assign a 2x3 matrix to table
$ table lists dimensions of table (e.g. 2 3)
gerbil =: 'maximus'
# gerbil returns 7
gerbil i. 'x' returns 2
a =: 'The answer is' ; 42
a contains The answer is 42 inside a box
0 { a returns The answer is
1 { a returns 42
a =: 7
b =: 7
a -: b -: is match, a matches b so it returns 1
3 3 $ 'xo' create a 3x3 matrix from characters xo
3 3 $ i.9 create a 3x3 matrix with the numbers 0 to 8
3 3 $ i._9 create a 3x3 matrix with the numbers 8 to 0
a =: 3 3 $ i.9
$ a returns shape of a which is 3 3
(< 1 ; 2) { a returns row 1, column 2 which is 5 in this case
3 >. 5 returns ceiling of 3 and 5 (e.g. 5)
3 <. 5 returns floor of 3 and 5 (e.g. 3)
'a' ,~ 'b' returns ba
b =: (i.10) +1 b equals the numbers 1 to 10
_1 { a returns last element of a
s =: 'pasta'
# s returns 5
z =: 8 {. pad out s to 8 charactes (with spaces)
|. 'cat' returns tac
load '~/j701/addons/ide/jhs/demo/jdemo1.ijs'
list
v =: i.10 v contains 0 to 9
p: v returns first 10 prime numbers