I am working on a one-sheet reference card for J. It looks like it will fit
on front & back of an 8.5x11 sheet if I use an 8-point font. I have a first
pass at what I want to include, attached to this email as a text file. I
would like comments from interested users before I go through the pain of
cramming it onto a page.
The intended user has a reading knowledge of J but may need some reminding
about what the primitives do. My goal is to include one example of all the
important idioms of J so that the interested user can look it up in more detail
if he finds it promising. The advanced reader who is trying to become expert in
J should feel that he has been exposed to most of the language once he has
finished
reading the reference card. Coders trying to remember a form should find
enough to
jog their memory.
I am going to group the J facilities by function: partitions, math, selection,
etc.
For each form, I have an example, my mnemonic, and a result. If the result
is an array it's not shown in the text file. The operands A and B are
a character array and a complex boxed structure which will be shown in the
legend.
I don't really expect anyone to review the attached notes in detail, but
if y'all would think a minute about what features you have found yourself
forgetting, or some feature you didn't find out about for years but now love,
let me know if you don't find it listed. I say nothing about useful verbs
from the J scripts and I welcome suggestions about what to mention.
Henry Rich
------------------------------------------------------------------------
<\ i. 3 Prefix 0;0 1;0 1 2
3 <\ i. 5 Infix 0 1 2;1 2 3;2 3 4
_3 <\ i. 5 Infix 0 1 2;3 4
<\. i. 3 Suffix 0 1 2;1 2;2
2 <\. i. 5 Outfix 2 3 4;0 3 4;0 1 4;0 1 2
_2 <\. i. 5 Outfix 2 3 4;0 1 4;0 1 2 3
([stepsize,:]shape) u;._3 y operates on regions of y with the given shape,
starting
at all possible multiples of items of stepsize. Negative items in shape run
that index
backwards
(3 4;2 2) u;._3 selects <approp part of 8x8 abc mtx>
u;.3 like u;._3, but undersize pieces at the boundaries are included
m\ m\. m;. m/. apply gerunds from m cyclically
([corner,:]length) u;.0 y operates on region of y. Negative in corner means
corner ends the interval; negative in length means axis is reversed
(1 _2,:3 2) ];.0 selects <approp part of abc mtx>
<;.1 'people' Cut 'peo';'ple'
<;._1 'people' Cut 'eo';'le'
<;.2 'people' Cut 'pe';'ople'
<;._2 'people' Cut 'p';'opl'
0 1 0 0 1 0 <;.1 i. 6 Cut 1 2 3;4 5
0 1 0 0 1 0 <;._1 i. 6 Cut 2 3;5
0 1 0 0 1 0 <;.2 i. 6 Cut 0 1;2 3 4
0 1 0 0 1 0 <;._2 i. 6 Cut 0;2 3
'people' </. i. 6 Key 0 3;1 5;2;4
<. 4.5 Floor 4
. 4.5 Ceiling 5
* y Sign _1, 0, or 1
! 4 Factorial 24
? y Random (result from i. y)
? 0 Random (result in interval (0,1))
<: y y-1
: y y+1
%y 1%y
-. y 1-y
+: y y*2
-: y y%2
*: y y*y
%: y sqrt(y)
^ y e^y
^. y e^.y
#. y 2#.y
#: y 2#:y (enough 2s as needed)
a&#.^:_1 y a#:y (enough as as needed)
2 + 8 Plus 10
2 - 8 Minus _6
2 * 8 Times 16
2 % 8 Divide 0.25
2 | 8 Residue 0
2 ^ 8 Exponent 256
2 ^. 8 Log 3
3 %: 8 Root 2
2 >. 6 Greater 6
2 <. 6 Lesser 2
36 *. 24 GCD 72
36 +. 24 LCM 12
10 10 10 #. 8 3 0 Base 830
10 10 10 #: 830 AntiBase 8 3 0
2 ! 8 OutOf 28
2 ? 8 Deal 4 2 (x values drawn from i. y without replacement)
x = y Equal
x ~: y Not-Equal
x > y Greater
x >: y Greater or Equal
x < y Less
x <: y Less or Equal
x -: y Match (Same rank, shape, boxing)
're' E. 'reread' WindowedMatch 1 0 1 0 0 0 (ranks can be > 1)
All comparisons can be followed by !.0 to make them Intolerant
-. y NOT
x *. y OR
x +. y AND
x +: y NOR
x *: y NAND
x m b. y (m 0-15) Boolean function with truth table 2 2#:4 4#:m, e. g. m=8 is
AND
x m b. y (m 16-31) bitwise Boolean, applies (m-16) b. to each bit of integers
x m b. y (m=32) left rotate (m=33) unsigned left shift (m=34) signed left shift
of x bit positions
ddxee ExponentialForm dd*e^ee
1x1 ExponentialForm 2.71828
ddpee CircleForm dd*pi^ee
1p1 CircleForm 3.14159
+ 3j4 Conjugate 3j_4
+. 3j4 Real/Imag 3 4
*. 3j4 Length/Angle 5 0.927
| 3j4 Magnitude 5
j. 1j2 TimesJ _2j1
3 j. 4 Complex 3j4
r. 0.25p1 Cis .7071j0.7071 e^j. y
x r. y CisTimes x * r. y
'people' -. 'po' RemoveItems 'ele'
~. 'people' Nub 'peol'
~: 'people' NubSieve 1 1 1 0 1 0
1 0 2 # 'abc' Copy 'acc'
1j1 0 2 # 'abc' CopyWithFill 'a cc'
1j1 0 2 #!.'*' CopyWithGivenFill 'a*cc'
_1 1 { A From (Items)
(<2 1) { A From (All axes scalar)
(<1 3;1 0 2) { A From (General Axes)
(<<1 3) { A From (Omitted trailing axis)
(<1 3 ,&< <2) { A From (complementary indexing of axis 1)
(<a:;2 0) { A From (Omitted early axis)
(<@[ { ]) FromUnboxed fast form when x unboxed
1 {:: B
(0;1) {:: B
(0;1 0) {:: B
2 {. i. 6 Take 0 1
_2 {. i. 6 Take 5 6
2 }. i. 6 Drop 2 3 4 5
_2 }. i. 6 0 1 2 3
5 {. 0 1 2 Overtake 0 1 2 0 0
5 {.!.9 (0 1 2) OvertakeWithFill 0 1 2 9 9
1 _2 {. A TakeMultiAxis
Table for monad {. etc.
I. 0 1 1 0 1 Indices 1 2 4
x ([: I. f) y IndicesWhereTrue fast form; f may be a comparison, e., or E.
1 0 1 0&#^:_1 (2 3) Expand 2 0 3 0
1 0 1 0&#^:_1!.9 (2 3) ExpandWithFill 2 9 3 9
'people' i. 'pow' IndexOf 0 2 6
'people' i: 'pow' IndexOfLast 3 2 6
'pow' e. 'people' 1 1 0
0 2 4 8 I. _1 2 2.5 9 InsertBeforePoint 0 1 2 4
(i. >./) IndexOfLargest fast form; i: and <. similarly
x (f i. 0:) y FindFirstFalse fast form; 1: and i: similarly. f may be a
comparison, e., or E.
m&i. DictSearch faster if many searches
%. y MatrixInverse
x %. y MatrixDivide
x +/ .* y MatrixMultiply
-/ .* y Determinant
+/ .* y Permanent
|. 'abcde' Reverse 'edcba'
2 |. 'abcde' RotateLeft 'cdeab'
_2 |. 'abcde' RotateRight 'deabc'
2 |.!.'*' ShiftLeft 'cde**'
|.!.'*' 'abcde' ShiftRight1 '*abcd'
1 _1 |. A RotateMultiAxis
|: A Transpose
x |: y ReorderAxes moves axes x to end of axes
/: 3 1 4 1 5 9 GradeUp 1 3 0 2 4 5
'abcdef' /: 3 1 4 1 5 9 SortUpUsing 'bdacef'
/:~ 3 1 4 1 5 9 SortUp 1 1 3 4 5 9
/:@/: 3 1 4 1 5 9 Ordinals 2 0 3 1 4 5
\: similarly, ordering down
'*' (<1 2)} A Amend
'*+' (([EMAIL PROTECTED])`([EMAIL PROTECTED])`])} A AmendGerund
y =. x i} y AmendInPlace fast form
(i. 2 2) , 8 9 Append
(i. 2 2) , ,8 AppendShort
(i. 2 2) , 8 AppendAtom
,. 'ab' RavelItems
'ab' ,. 'cd' AppendItems
$ ,: 'ab' Itemize 1 2 (adds leading axis)
'ab' ,: 'cd' Laminate
3 $ i. 2 2 ReshapeItems
3 ($,) i. 2 2 Reshape
3;(4;5) Link
3,&<(4;5) JoinBoxed
; (i. 2 2);(,4);6 Raze expands items to size of largest, like ,, then appends
;: 'two words' Words 'two';'words'
;:^:_1 'two';'words' StringFromWords 'two words'
L. B Level
$ L:0 B AtLevel
$ S:0 B Spread
|.&.> B Each (Use Where Possible)
". '2 + 3' Execute 5
5j2 ": 1.468 2.3 Format 1.47 2.30
7j_2 ": 2.3 Format 2.30e0
'b<unch>p<+>m<->6.2q<%>n<%>' 8!:2 ]_4 0 5.2 Format -4.00 unch +5.20
u/ y Insert insert u between elements of y and evaluate
m/ y InsertGerund insert verbs from gerund m cyclically
u~ y Reflex y u y
x u~ y Exchange y u x
u^:n Power u n times
[x] u^:v y If if [x] v y is 0, y; if 1, [x] u y
u^:_ Converge repeat u till result is constant
[x] u^:v^:_ y DoWhile repeat u while [x] v y is 1
u^:a: ConvergeHistory repeat u till result is constant, returning all
intermediate values
{&0^:a: ChaseChain follow chain of record lengths
u^:_1 Inverse Apply inverse of u
u:.v Inverse u, but with inverse v
u::v Adverse u, but execute v if error in u
[x] u@:v y At u [x] v y
[EMAIL PROTECTED] Atop u@:v"mv
[x] u&:v y Appose [v x] u v y
u&v Compose u&:v"mv
[x] u&.:v y Dual v^:_1 [v x] u v y
u&.v Dual u&.:v"mv
[x] u0`u1`... @.v y Agenda execute gerund indexed by [x] v y
u`v TwoGerunds
u`'' OneGerund
+:`-: `:0 i. 3 Append
+`'' `:6 MakeVerb +
x u/ y Table Apply each CELL of x to ENTIRE y
'n1 n2' =. v1;v2 AssignMult One level of boxing is removed
(n) =. v AssignInd Value of n gives the names to assign
'`add sub' =. +`- AssignAR
A. 2 0 1 AnagramIndex 4
4 A. 'abc' Anagram cab
C. 2 1 0 PermForm 1;2 0
C. 1;2 0 PermForm 2 1 0
(1;2 0) C. 'abc' Permute 'cba'
p: 3 YthPrime 7
x p: y PrimeInfo
q: 56 PrimeFactors 2 2 2 7
_ q: 56 PrimeExponents 3 0 0 1
__ q: 56 PrimeFacExp
x: 1%3 Exact 1r3
x:^:_1 (1r3) Inexact 0.33333
2 x: 1r3 NumDenom 1 3
1 o. 1r3p1 Sin 0.866
2 o. 1r3p1 Cos 0.5
other o.s...
p. 6 5 1 Roots 1;_3 _2
p. 2;_3 _2 Coeffs 12 10 2
1 2 1 p. 2 EvalPoly 9
(1;_1 _1) p. 2 EvalPoly 9
p. 1 2 1 PolyDeriv 2 2
9 p. 1 2 1 PolyIntegral 9 1 1 0.33
*: d. 1 Derivative +:
*: D. 1 PartDeriv (* =/~@([EMAIL PROTECTED]))@:+:
*:`+: D. 1 AssignDeriv
1e_8 u D: n y SecantSlope of nth deriv
^ t. 1 2 3 TaylorCoeff 1 0.5 0.167
u`v t. n AssignTaylor
^ t: 1 2 3 ExpTaylor 1 1 1
^ T. 3 TaylorApprox 1 1 0.5&p. (verb result)
m H. n HypergeometricSeries
: b. _1 ShowInverse <:
: b. 0 ShowRanks 0 0 0
: b. 1 ShowIdentity 1 $~ [EMAIL PROTECTED]
s: Symbols
u: Unicode
$. Sparse
1!:n File Operations
3!:0 y Datatype of y
3!:1 y Binary rep of y (coded characters)
3!:3 y Hex rep of y (displayable characters)
x 3!:4 y if x e. 1 2 3, convert integer list y to character list, 2^x chars per
number
if x e. _1 _2 _3, convert char list y to integer list, 2^-x chars per number
if x=0, result is 65536 | _1 (3!:4) y (unsigned 2-char numbers)
x 3!:5 y if x e. 1 2, convert float list y to character list, 2^>:x chars per
number
if x e. _1 _2, convert char list y to float list, 2^>:-x chars per number
4!:0 <'name' Class of name, _1 if undefined
5!:5 <'name' String which, when interpreted, creates vbl name
6!:0 '' current time YMDHMS
[x] 6!:2 'sentence' time to execute sentence x times
7!:2 'sentence' space to execute sentence
------------------------------------------------------------------------
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm