- •Foreword
- •1. Introduction
- •2. Culture Shock
- •3. Preliminaries
- •Notation Used in This Book
- •Terminology
- •Sentences (statements)
- •Word Formation (tokenizing rules)
- •Numbers
- •Characters
- •Valence of Verbs (Binary and Unary Operators)
- •How Names (Identifiers) Get Assigned
- •Order of Evaluation
- •How Names Are Substituted
- •What a verb (function) looks like
- •Running a J program
- •The Execution Window; Script Windows
- •Names Defined at Startup
- •Step-By-Step Learning: Labs
- •J Documentation
- •Getting Help
- •4. A First Look At J Programs
- •Average Daily Balance
- •Calculating Chebyshev Coefficients
- •5. Declarations
- •Arrays
- •Cells
- •Phrases To Memorize
- •Constant Lists
- •Array-creating Verbs
- •6. Loopless Code I—Verbs Have Rank
- •Examples of Implicit Loops
- •The Concept of Verb Rank
- •Verb Execution—How Rank Is Used (Monads)
- •Controlling Verb Execution By Specifying a Rank
- •Examples Of Verb Rank
- •Negative Verb Rank
- •Verb Execution—How Rank Is Used (Dyads)
- •When Dyad Frames Differ: Operand Agreement
- •Order of Execution in Implied Loops
- •A Mistake To Avoid
- •7. Starting To Write In J
- •8. More Verbs
- •Arithmetic Dyads
- •Boolean Dyads
- •Min and Max Dyads
- •Arithmetic Monads
- •Boolean Monad
- •Operations on Arrays
- •9. Loopless Code II—Adverbs / and ~
- •Modifiers
- •The Adverb Monad u/
- •The adverb ~
- •10. Continuing to Write in J
- •11. Boxing (structures)
- •Terminology
- •Boxing As an Equivalent For Structures In C
- •12. Compound Verbs
- •Verb Sequences—u@:v and u@v
- •Making a Monad Into a Dyad: The Verbs [ and ]
- •Making a Dyad Into a Monad: u&n and m&v
- •13. Empty Operands
- •Execution On a Cell Of Fills
- •Empty cells
- •If Fill-Cells Are Not Enough
- •14. Loopless Code III—Adverbs \ and \.
- •15. Verbs for Arithmetic
- •Dyads
- •Monads (all rank 0)
- •16. Loopless Code IV
- •A Few J Tricks
- •Power/If/DoWhile Conjunction u^:n and u^:v
- •Tie and Agenda (switch)
- •17. More Verbs For Boxes
- •Dyad ; (Link) And Monad ; (Raze)
- •Dyad { Revisited: the Full Story
- •Split String Into J Words: Monad ;:
- •Fetch From Structure: Dyad {::
- •Report Boxing Level: Monad L.
- •18. Verb-Definition Revisited
- •What really happens during m :n and verb define
- •Compound Verbs Can Be Assigned
- •Dual-Valence verbs: u :v
- •The Suicide Verb [:
- •Multi-Line Comments Using 0 :0
- •Final Reminder
- •The Obverse u^:_1
- •Apply Under Transformation: u&.v and u&.:v
- •Defined obverses: u :.v
- •An observation about dyadic verbs
- •20. Performance: Measurement & Tips
- •Timing Individual Sentences
- •Compounds Recognized by the Interpreter
- •Use Large Verb-Ranks! and Integrated Rank Support
- •Shining a Light: The J Performance Monitor
- •21. Input And Output
- •Foreigns
- •File Operations 1!:n; Error Handling
- •Treating a File as a Noun: Mapped Files
- •Format Data For Printing: Monad And Dyad ":
- •Format an Array: 8!:n
- •Format binary data: 3!:n
- •printf, sprintf, and qprintf
- •Convert Character To Numeric: Dyad ".
- •22. Calling a DLL Under Windows
- •Memory Management
- •Aliasing of Variables
- •23. Socket Programming
- •Asynchronous Sockets and socket_handler
- •Names and IP Addresses
- •Connecting
- •Listening
- •Other Socket Verbs
- •24. Loopless Code V—Partitions
- •Find Unique Items: Monad ~. and Monad ~:
- •Apply On Subsets: Dyad u/.
- •Apply On Partitions: Monad u;.1 and u;.2
- •Apply On Specified Partitions: Dyad u;.1 and u;.2
- •Apply On Subarray: Dyad u;.0
- •Apply On All Subarrays: Dyad u;.3 and u;._3
- •Extracting Variable-Length Fields Using ^: and ;.1
- •Example: Combining Adjacent Boxes
- •25. When Programs Are Data
- •Calling a Published Name
- •Using the Argument To a Modifier
- •Invoking a Gerund: m`:6
- •Passing the Definition Of a Verb: 128!:2 (Apply)
- •Passing an Executable Sentence: Monad ". and 5!:5
- •26. Loopless Code VI
- •28. Modifying an array: m}
- •Monad I.—Indexes of the 1s in a Boolean Vector
- •29. Control Structures
- •while./do./end. and whilst./do./end.
- •if./do./else./end., if./do./elseif./do./end.
- •try./catch./catcht./end. and throw.
- •return.
- •assert.
- •30. Modular Code
- •Locales And Locatives
- •Assignment
- •Name Lookup
- •Changing The Current Locale
- •The Shared Locale 'z'
- •Using Locales
- •31. Writing Your Own Modifiers
- •Modifiers That Do Not Refer To x. Or y.
- •Modifiers That Refer To x. Or y.
- •32. Applied Mathematics in J
- •Complex Numbers
- •Matrix Operations
- •Calculus: d., D., D:, and p..
- •Taylor Series: t., t:, and T.
- •Hypergeometric Function with H.
- •Sparse Arrays: Monad and Dyad $.
- •Random Numbers: ?
- •Computational Addons
- •Useful Scripts Supplied With J
- •33. Elementary Mathematics in J
- •Verbs for Mathematics
- •Extended Integers, Rational Numbers, and x:
- •Factors and Primes: Monad p:, Monad and Dyad q:
- •Permutations: A. and C.
- •34. Graphics
- •Plot Package
- •2D Graphics: the gl2 Library
- •Displaying Tabular Data: the Grid Control
- •3D Graphics: OpenGL
- •35. Odds And Ends
- •Dyad # Revisited
- •Boxed words to string: Monad ;:^:_1
- •Spread: #^:_1
- •Choose From Lists Item-By-Item: monad m}
- •Recursion: $:
- •Make a Table: Adverb dyad u/
- •Cartesian Product: Monad {
- •Boolean Functions: Dyad m b.
- •Operations Inside Boxes: u L: n, u S: n
- •Comparison Tolerance !.f
- •Right Shift: Monad |.!.f
- •Generalized Transpose: Dyad |:
- •Monad i: and Dyad i:
- •Fast String Searching: s: (Symbols)
- •Fast Searching: m&i.
- •CRC Calculation
- •Unicode Characters: u:
- •Window Driver And Form Editor
- •Tacit Programming
- •36. Tacit Programs
- •37. First Look At Forks
- •38. Parsing and Execution I
- •39. Parsing and Execution II
- •The Parsing Table
- •Examples Of Parsing And Execution
- •Undefined Words
- •40. Forks, Hooks, and Compound Adverbs
- •Tacit and Compound Adverbs
- •Referring To a Noun In a Tacit Verb
- •41. Readable Tacit Definitions
- •Flatten a Verb: Adverb f.
- •Special Verb-Forms Used in Tacit Definitions
- •43. Common Mistakes
- •Mechanics
- •Programming Errors
- •44. Valedictory
- •45. Glossary
- •46. Error Messages
- •47. Index
46. Error Messages
When J encounters an error executing a sentence it stops and displays the sentence. The interpreter removes any excess spaces from the sentence and then adds three spaces before the word whose execution triggered the error. For example:
|
2 3 + 0 1 2 * 3 4 5 |
||
|length |
error |
1 2*3 4 5 |
|
| |
2 3 |
+0 |
The error occurred during the execution of the + verb.
The errors you are most likely to encounter are:
control error If the error is detected when a script is loaded, you have an incomplete control structure, for example an if. without matching do./else./elseif. and end. or, notoriously, the sequence if./elseif./else., which is not allowed (use elseif. instead of that last else.). If the error is detected when a script is executed, you have an if. block whose last line does not produce a noun result, like if. undefname do. .
domain error An operand has a value that is not allowed, for example a string operand to an arithmetic operation, or an out-of-range numeric left operand to dyad o. . One common source of domain error is trying to execute a verb when no definition exists for the valence (monadic or dyadic) that you are trying to execute.
Errors encountered during execution of wd are reported as domain errors.
file name error You specified a file name that is invalid, or attempted to read a nonexistent file.
file number error You specified a number that is not the number of an open file.
ill-formed name You used an illegal name, such as name_1ff_ (illegal because 1ff is not a valid locale name)
ill-formed number You used an illegal number such as 14h . A word that starts with a numeric character must be a valid number, and vice versa.
index error You attempted to access an element outside the bounds of an array.
length error You used a dyadic verb with operands that did not agree (i. e. one frame was not a prefix of the other). Or, a verb expected an operand of a certain length and you gave an incorrect length (for example 1 2 3 {. 5 5)
limit error You exceeded one of J's limits, for example by specifying a comparison tolerance greater than 2^_34 . The most common cause of a limit error is an infinite recursion that exhausts the available stack space.
nonce error You tried to do something reasonable, but the system doesn't support it yet. So, for the nonce, find another way to do it.
open quote Your sentence contains an unmatched single-quote.
250
out of memory The interpreter asked the operating system for enough memory to fulfill your request, but the operating system refused. You need to use smaller nouns, or have a bigger virtual-memory swap file, or close other programs that are competing for virtual memory space.
rank error You specified an operand with an invalid rank.
spelling error You typed an erroneous . or : to produce a meaningless word like +.. or fred. .
syntax error Your sentence contains an invalid sequence of parts of speech, as in 5 + . Or, you have an explicitly-defined verb whose last-executed sentence gives a result that is not a noun: that would make the verb have a non-noun result, which is intolerable.
value error You have asked the interpreter to evaluate a name that has not been defined. There is more to this definition than meets the eye. A noun, adverb, or conjunction is evaluated when it is encountered during the right-to-left execution of a sentence. A verb is evaluated when (a) it is executed with its noun operand(s) or (b) when the name of the verb is typed as the only word in a sentence, at which time the verb is evaluated for display purposes. For example, the sentence
undefname
will result in a value error, because you are asking the interpreter to display the value of the undefined name. However, the sentence
name =: undefname
will not fail, because name is defined to be a reference to undefname, and undefname does not have to be evaluated (the undefined name is assumed to refer to a verb of infinite rank that will be defined later). Subsequently,
name undefname
name is defined, but if we force the interpreter to use it:
|
name 5 |
|value error: undefname |
|
| |
name 5 |
the underlying undefined name is exposed.
An important case is: undefname1 undefname2
undefname1 undefname2
Note that this did not result in a value error. Recall that undefined names are assumed to be verbs; we defined a hook from the two presumed verbs and then asked the interpreter to display the hook. The interpreter was able to do that without evaluating either name. Either name by itself would produce a value error.
251
47. Index
- dyad · 54
!
!dyad · 93, 190
!monad · 94, 184 !. · 59, 213 !: · 125
"
" · 37
".dyad · 128, 131
".monad · 156
": dyad · 127
#
#dyad · 57, 207
#monad · 30
#.dyad · 93
#.monad · 33 #: dyad · 93 #: monad · 33
#^:_1 dyad · 207
$
$ dyad · 25 $ monad · 27 $. dyad · 188
$. monad · 188 $: · 208
%
% dyad · 54 %: dyad · 93
%: monad · 94
*
*dyad · 54
*monad · 55 *: monad · 94
,
,dyad · 44, 103
,monad · 62
,. dyad · 59 ,: dyad · 60 ,: monad · 64
.
Apply On All Subarrays conjunction · 149
Apply On Partitions conjunction · 145 Apply On Selected Partitions
conjunction · 146
Apply On Subarray conjunction · 148
. dyad · 55, 190 -. dyad · 57
. monad · 184 -. monad · 55 u;.3 and u · 149 u · 148 u;.1and u · 146 u;.1 and u · 145
/
-/ .* · 184 /: dyad · 61
/: monad · 63
252
:
:dyad · 61 -: dyad · 62
:monad · 63 -: monad · 94
;
;dyad · 101
;monad · 102 ;: dyad · 161 ;: monad · 107
;:^:_1 monad · 207
?
? · 188
[
[ · 84 [: · 112
]
] · 84
^
^dyad · 54
^monad · 94 ^. dyad · 54 ^. monad · 94
{
{dyad · 56 details · 104
{monad · 209 {. dyad · 58 {. monad · 63 {: monad · 63 {:: dyad · 107
|
| dyad · 54
| monad · 55, 184 |. dyad · 60
|. monad · 63 |.!.f monad · 213 |: dyad · 214
|: monad · 63
}
}.dyad · 58
}.monad · 63 }: monad · 63
~
~ · 68
~. monad · 143 ~: dyad · 54, 55 ~: monad · 143
+
+dyad · 54
+monad · 184 +. dyad · 55, 190 +. monad · 184 +/ .* · 184
+: monad · 94
<
<dyad · 54
<monad · 76 <. dyad · 55 <. monad · 55 <: dyad · 55 <: monad · 55
=
= dyad · 54, 55
253
>
> dyad · 54
>.dyad · 55
>.monad · 55 >: dyad · 55 >: monad · 55
1
128!:2 dyad · 155 128!:3 · 216
8
8!:n · 129
9
9!:18 · 213 9!:19 · 213
A
A.dyad · 192
A.monad · 192 a: · 77
addons · 189
agreement of operands · 45 aliasing · 135
Amend adverb } · 164 Anagram Index verb A. · 192 anonymous entity · 7 Antilog verb ^ · 94
Append verb , · 44, 103
Apply At Level conjunction L: · 211 Apply On Subsets adverb /. · 143 Apply Under Transformation
conjunction &. · 114 Apply Under Transformation
conjunction &.: · 115 Apply verb 128!:2 · 155 array · 22
assignment · 10 multiple · 103
private · 170 public · 171
atom · 23
atomic representation · 99 axis · 24
order · 24
B
Behead verb }. · 63
bitwise Boolean functions · 210 bitwise left rotate · 210
bitwise signed left shift · 210 bitwise unsigned left shift · 210 Boolean Functions verb m b. · 210 Box verb < · 76
boxing · 76
C
C
belittled · ii derided · 51
J equivalent for class · 170 structure equivalent in J · 79
C. dyad · 192 C. monad · 191
C.!.2 monad · 192 calculus · 186
polynomials · 187 calling a DLL · 133 Cartesian product · 209 cd verb · 133
cell · 23
character constants · 9, 25 comments in code · 113 comparison tolerance !. · 54, 213 complex numbers · 184 compound adverbs · 234 compound verb · 80
Constant verb m"n · 64 control error · 250 control structures · 167
assert. · 169 catcht. throw. · 168 for. do. end. · 167
254
if. do. else. elseif. end. · 167 return. · 169
select. case. end. · 168 try. catch. end. · 168
while. whilst. do. end. · 167 conversions · 135
copula · 10 Copy verb # · 57
CRC calculation · 216 Curtail verb }: · 63 Cycle verb C. · 191
D
Deal verb ? · 188 defnouns · 40 defverbs · 40 derivative · 186
approximate · 187 partial · 186
derived entity · 7 derived verb · 80 Do verb ". · 156 domain error · 250
DoWhile conjunction u^:v^:_ · 98 Drop verb }. · 58
E
e. dyad · 58 E. dyad · 147
Element Of verb e. · 58 empty cells · 89
empty operands · 87 Enfile verb , · 62 entity · 6
error handling · 126, 168 Extended integers · 190 Extended Precision verb x: · 191
Extracting variable-length records · 150
F
f. · 236
Factorial verb ! · 94, 184 fast searches · 216
Fetch verb {:: · 107 FFT addon · 189 file name error · 250
file number error · 250 fill · 77
framing · 40 verb · 59
with empty operands · 87 Find Insertion Point verb I. · 58 Find Sequence verb E. · 147 Fit conjunction !. · 59
Flatten adverb · 236 fndisplay · 40
Foreign conjunction !: · 125 form editor · 216
format for printing · 127, 129 frame · 23, 34, 42
From verb { · 56
G
generalized hypergeometric function · 188
gerund · 99
Grade verbs /: \: · 63 Graphics
command summary · 202 creating an isigraph · 200 drawing graphics · 201 drawing surface · 202 drawing text · 201 example · 200
graphics blocks · 205 Grid Control · 206 isigraph events · 205 OpenGL · 206
screen addressing · 201 selecting an isigraph · 201
Greatest Common Divisor verb +. · 190
H
Head verb {. · 63 hypergeometric function · 188
255
I
i.dyad · 57 i.!.0 · 58, 213
I. dyad · 58 i. monad · 30
I. monad · 165 i: · 214
identity element · 68 Identity verbs [ ] · 84 If conjunction ^: · 97 ill-formed name · 250 ill-formed number · 250 index error · 250
Index Of verb i. · 57 Indexes verb I. · 165 Infix adverb · 91 input and output · 125
integrated rank support · 121 interrupting execution · 14 inverse of verb · 114
Invoke Gerund conjunction `: · 154 item · 24
Itemize verb ,: · 64
J
J Forum · 16 j. dyad · 184 j. monad · 184
L
L. monad · 108 L: · 211
Labs · 15
Laminate verb ,: · 60 LAPACK addon · 189 length error · 250 Level verb L. · 108 limit error · 250
Link verb ; · 101 list · 24
load verb · 13 locale
changing current · 172
current · 170 defined · 170 locative · 170 name lookup · 171 search path · 171
used for modular programming · 175 z · 175
Log verb ^. · 94
Lowest Common Multiple verb . · 190
M
m :n · 110 m b. · 210 m D. n · 187 m H. n · 188 m"n · 64 m&i. · 216
m&v dyad · 240 m&v monad · 85 m@.v · 100 m`:6 · 154
m} dyad · 164 m} monad · 207 mapped files · 126 Match verb -: · 62 matrix verbs · 184
memory management · 134 mema · 134
memf · 134 memr · 135 memw · 134
modification in place · 166, 207 modifier · 7
user-defined · 177 Modifier
order of execution · 66 Modify adverb } · 164 modular code · 170 multinomials · 185
N
name · 7
nonce error · 250 nouns in forks · 231
256
Nub Sieve verb ~: · 143 Nub verb ~. · 143
Number Of Combinations verb ! · 93, 190
Numbers verb ". · 131
O
o. (trigonometric function) · 55 obverse of verb · 114
defined by u :.v · 116 discussed under ^: · 114
open quote error · 250 operand passing
by name · 179 by value · 179
order of execution in implied loops · 49 out of memory error · 251
P
p. dyad · 185 p. monad · 185 p.. dyad · 187 p.. monad · 187 p: monad · 191 Partitions
implied · 145 multidimensional · 148 specified · 146
parts of speech · 6
passing a verb as an argument · 153 performance measurement · 118 Performance Monitor · 122 permutation parity · 192 permutations
direct representation · 191 standard cycle representation · 191
Permute verb C. · 192 Plot
annotation · 195 captions · 195 colors · 194 data · 195
fonts · 194 functions · 197
labels · 195 options · 194 parametric · 199 printing · 199
starting and ending · 196 steps verb · 197
title · 195
Plot Package · 193
Polynomial Derivative verb p.. · 187 Polynomial Integral verb p.. · 187 Polynomial verb p. · 185 polynomials · 185
calculus · 187
Power conjunction ^: · 96 a: as operand · 150
Prime Exponents verb q: · 191 Prime Factors verb q: · 191 Primes verb p: · 191 primitive · 7
printf · 131
priority of number representation · 190 Profile · 15
punctuation · 7
Q
q: dyad · 191 q: monad · 191
R
r. dyad · 184 r. monad · 184
random numbers · 188 rank · 22, 27, 30, 34, 111
negative · 41
Rank conjunction " · 37 rank error · 251 Rational numbers · 190 Ravel verb , · 62
Raze verb ; · 102 recursion · 208 Remove verb -. · 57 removing a name · 15
result to produce no typeout · 28 Reverse verb |. · 63
257
Right Shift verb |.!.f · 213 Roll verb ? · 188
Root verb %: · 93 Roots verb p. · 185 Rotate Left verb |. · 60
S
s
monad and dyad · 215 S: · 211
scalar · 23 scripts
supplied with J · 189 sentence · 7
Sequential machine · 161 setfnform · 40
shape · 22
Shift Left verb |.!.f · 60 sockets · 138
datagrams · 141 IP addresses · 139 sdaccept · 141 sdasync · 138 sdbind · 141 sdcleanup · 142 sdclose · 140 sdconnect · 140
sdgethostbyaddr · 139 sdgethostbyname · 139 sdgethostname · 139 sdgetpeername · 139 sdgetsockets · 142 sdgetsockopt · 142 sdioctl · 142
sdlisten · 141 sdrecv · 140 sdrecvfrom · 141 sdselect · 138 sdsend · 140 sdsendto · 141 sdsocket · 138 setsockopt · 142 socket options · 141 socket_handler · 139
Sort Using verb /: \: · 61
Sort verb /: \: · 61 sparse arrays · 188
special code in the interpreter · 120 spelling error · 251
Spread verb #^:_1 · 207 Square Root verb %: · 94 steps verb · 197
Stitch verb ,. · 59 string matching · 215 Suicide verb [: · 112 symbols · 215 syntax error · 251
T
Table adverb / · 208 tacit adverbs · 234 tacit programming
anonymous verb · 222 explicit-to-tacit converter · 239 fork · 220
forks and hooks · 231 improving readability · 236 introduction · 218
parsing and execution · 222 parsing table · 225 summary of execution · 225 trains · 220
Tail verb {: · 63 Take verb {. · 58 Taylor series · 187 Tie conjunction ` · 99
Transpose verb |: · 63, 214 type · 23
U
u ::v · 126 u :v · 112 u d. n · 186 u D. n · 186 u D: n · 187 u\ dyad · 91
u f`g`h} y · 240 u\ monad · 90 u t. · 187
258
u T. n · 187 u t: · 187 u"n · 37 u&.:v · 115 u&.v · 114 u&:v · 116
u&n dyad · 240 u&n monad · 85 u&v · 116
u\. dyad · 92 u\. monad · 91 u/ dyad · 208 u/ monad · 66 u/. dyad · 143 u@:v dyad · 80 u@v dyad · 81 u\\. monad
for performance · 120 u^:_1 (obverse) · 114 u^:n · 96
u^:v · 97 u`v · 99
undefined names · 230 Unicode verb u: · 216
V
valence · 9, 112 value error · 251 verb
definition · 110
W
window driver · 216 word · 6, 8
X
x: dyad · 191 x: monad · 191
259