>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  J for C Programmers

Contents

Foreword. ii

Acknowledgements. iii

Change History. iii

1.   Introduction. 13

2.   Culture Shock. 14

Programming In J  17

3.   Preliminaries. 18

Notation Used in This Book. 18

Terminology. 18

Sentences (statements) 19

Comments. 19

Word Formation (tokenizing rules) 19

Numbers. 20

Adjacent Numbers Form a Single Word. 20

Adjacent Named Nouns Do NOT Form a Single Word. 21

Characters. 21

Valence of Verbs (Binary and Unary Operators) 21

How Names (Identifiers) Get Assigned. 22

Order of Evaluation. 23

How Names Are Substituted. 23

What a verb (function) looks like. 24

Running a J program.. 25

Interrupting Execution. 27

Errors. 27

The Execution Window; Script Windows. 27

Names Defined at Startup. 28

Step-By-Step Learning: Labs. 28

J Documentation. 28

Reference Card. 29

Getting Help. 29

4.   A First Look At J Programs. 30

Average Daily Balance. 30

Calculating Chebyshev Coefficients. 33

5.   Declarations. 35

Arrays. 35

Cells. 36

Choosing Axis Order 37

Negative Cell-Rank; Items. 37

Lists. 38

Phrases To Memorize. 38

Constant Lists. 39

Array-creating Verbs. 39

Dyad $ ($hape) and monad $ ($hape Of) 39

Monad # (Tally) 44

Monad i. (Integers) 44

6.   Loopless Code I: Verbs Have Rank. 46

Examples of Implicit Loops. 46

The Concept of Verb Rank. 48

Verb Execution--How Rank Is Used (Monads) 48

Controlling Verb Execution By Specifying a Rank. 50

Examples Of Verb Rank. 51

Fills. 54

fndisplay--A Utility for Understanding Evaluation. 54

Negative Verb Rank. 55

Rank Makes Verbs Automatically Extensible. 56

Verb Execution--How Rank Is Used (Dyads) 56

Concatenating Lists: Dyad , (Append) 59

When Dyad Frames Differ: Operand Agreement 60

Order of Execution in Implied Loops. 64

Nested Loops. 64

A Mistake To Avoid. 66

7.   Starting To Write In J. 68

8.   More Verbs. 71

Arithmetic Dyads. 71

Boolean Dyads. 72

Min and Max Dyads. 72

Arithmetic Monads. 72

Trigonometric Functions. 72

Boolean Monad. 73

Operations on Arrays. 73

Dyads. 73

Monads. 80

9.   Loopless Code II: Adverbs / and ~.. 84

Modifiers. 84

What 'Monadic' and 'Dyadic' Mean For Modifiers. 84

The Adverb Monad u/ (Insert) 85

The adverb ~. 87

10. Continuing to Write in J. 89

Example: Counting Words and Lines. 93

11. Boxing (structures) 95

Terminology. 97

Boxing As an Equivalent For Structures In C.. 98

12. Compound Verbs. 99

Verb Sequences--u@:v and u@v.. 99

The Difference Between u@:v and u@v.. 100

An Exercise in @ and @:.. 101

Making a Monad Into a Dyad: The Verbs [ and ] 103

Making a Dyad Into a Monad: u&n and m&v.. 104

The Invisible Modifiers: Hooks and Forks. 105

13. Empty Operands. 107

Execution On a Cell Of Fills. 107

Empty cells. 109

If Fill-Cells Are Not Enough. 109

14. Loopless Code III--Adverbs \ and \... 110

When There Are No Subsets. 112

15. Verbs for Arithmetic. 114

Dyads. 114

Monads (all rank 0) 115

16. Loopless Code IV: Irregular Operations. 116

A Few J Tricks. 116

Power/If/DoWhile Conjunction u^:n and u^:v.. 118

Applying u Repeatedly (Power) 118

Applying u Optionally (If) 119

Applying u Forever (Converge) 119

Applying u Iteratively (DoWhile) 119

Tie and Agenda (switch) 120

The Tie Conjunction u`v u`n m`v m`n.. 120

The Agenda (switch) conjunction m@.v.. 121

17. More Verbs For Boxes. 123

Box and Join: Dyad ; (Link) 123

Unbox and Join: Monad ; (Raze) 124

Dyad , Revisited--the Case of Dissimilar Items. 125

Verbs With Many Operands--Multiple Assignment 125

Dyad { Revisited: The Full Story. 126

Simplification 1: Remove Inner Boxing If Selectors Are Scalars. 128

Simplification 2: Remove All Boxing To Select Full Items. 129

Split String Into J Words: Monad ;:.. 129

Fetch From Structure: Dyad {::.. 130

Report Boxing Level: Monad L... 131

18. Verb-Definition Revisited. 133

What really happens during m :n and verb define.. 133

Compound Verbs Can Be Assigned. 134

Dual-Valence verbs: u :v.. 135

The Suicide Verb [:.. 135

Multi-Line Comments Using 0 :0.. 136

Final Reminder 136

19. u^:_1, u&.v, u&.:v, and u :.v.. 137

The Obverse u^:_1.. 137

Apply Under Transformation: u&.v and u&.:v.. 137

Defined obverses: u :.v.. 139

u&:v and u&v.. 139

In dyadic verbs, x is control and y is data. 140

20. Input And Output 141

Foreigns. 141

File Operations 1!:n; Error Handling. 141

Error Handling: u ::v, 13!:11, and 9!:8.. 142

Treating a File as a Noun: Mapped Files. 142

Format Data For Printing: Monad And Dyad ":.. 143

Monad ":.. 144

Format an Array: 8!:n.. 145

Format binary data: 3!:n.. 146

printf, sprintf, and qprintf.. 147

Convert Character To Numeric: Dyad "... 147

21. Calling External Programs. 149

Calling a DLL.. 149

Naming the Procedure. 149

Describing the Operands and Result 150

Supplying the Operand Data. 150

Options. 151

Errors. 151

Memory Management 151

Filling a Structure: Conversions. 152

Aliasing of Variables. 152

Aliasing of Mapped Nouns. 153

Aliasing of DLL Operands. 153

22. Socket Programming. 155

sdselect.. 155

Asynchronous Sockets and socket_handler.. 155

Names and IP Addresses. 156

Connecting. 157

Listening. 157

Other Socket Verbs. 158

Datagrams. 158

Socket Options. 158

Housekeeping. 159

23. Loopless Code V: Partitions. 160

Find Unique Items: Monad ~. and Monad ~:.. 160

Apply On Subsets: Dyad u/... 160

Apply On Partitions: Monad u;.1 and u;.2.. 162

Creating An Array Using 0 :0 And ;._2.. 163

Apply On Specified Partitions: Dyad u;.1 and u;.2.. 164

Find Sequence Of Items: Dyad E... 164

Multidimensional Partitions. 165

Apply On Subarray: Dyad u;.0.. 165

Apply On All Subarrays: Dyad u;.3 and u;._3.. 167

Extracting Variable-Length Fields Using ^:a: and ;.1.. 168

Example: Combining Adjacent Boxes. 169

24. When Programs Are Data. 171

Calling a Published Name. 171

Using the Argument To a Modifier 171

Invoking a Gerund: m`:6.. 172

Passing the Definition Of a Verb: 128!:2 (Apply) 173

Passing an Executable Sentence: Monad ". and 5!:5.. 174

25. Loopless Code VI: Temporary Variables. 175

26. Loopless Code VII: Sequential Machines. 179

27. Modifying an array: m}.. 183

Monad I.--Indexes of the 1s in a Boolean Vector 184

Modification In Place. 185

28. Control Structures. 186

for./do./end. and for_x./do./end... 186

while./do./end. and whilst./do./end... 186

if./do./else./end., if./do./elseif./do./end... 186

try./catch./catcht./end. and throw... 187

select./case./fcase./end... 187

return... 188

assert... 188

29. Modular Code. 189

Locales And Locatives. 189

Assignment 189

Referencing a Name: Scope. 190

Referencing a Public Name: The Search Path. 191

Changing The Current Locale. 192

True Globals--The Shared Locale 'z'.. 194

Using Locales--Object-Oriented Programming. 194

Object-Oriented Programming in J: Base Classes. 194

Object-Oriented Programming in J: Derived Classes. 196

Object-Oriented Programming in J: Objects. 196

Good Object-Oriented Design in J. 199

Other Uses of Locales in J. 199

30. Writing Your Own Modifiers. 201

Modifiers That Do Not Refer To x Or y.. 201

Example: Creating an Operating-System-Dependent Verb. 202

Example: The LoopWithInitial Conjunction. 203

Example: A Conjunction that Analyzes u and v.. 204

An Exception: Modifiers that Do Not Refer to u or v.. 205

Modifiers That Refer To x Or y.. 206

31. Applied Mathematics in J. 208

Radix Notation For Numbers. 208

Complex Numbers. 208

Matrix Operations. 209

Polynomials: p... 209

Calculus: d., D., D:, and p.... 210

Taylor Series: t., t:, and T... 212

Hypergeometric Function with H... 212

Sparse Arrays: Monad and Dyad $... 212

Random Numbers: ?.. 213

Computational Addons. 213

Useful Scripts Supplied With J. 213

32. Elementary Mathematics in J. 214

Verbs for Mathematics. 214

Exact Arithmetic: Extended and Rational Numbers. 214

Changing Precision: Monad and Dyad x:.. 215

Understanding Precision. 215

Factors and Primes: p: and q:.. 216

Permutations: A. and C... 217

33. Graphics. 219

Plot Package. 219

Plot Demo. 219

Interfaces to Plot 219

Commands and Options. 220

Data; Constructing a Plot with pd.. 221

Quick Plots Using plot.. 222

Generating Plots of Functions. 223

Assembling a Multipart Plot with pd.. 224

Examples of Plots with Multiple Sets of Points. 225

Plots of Parametric Functions. 225

Output Options. 225

2D Graphics: the gl2 Library. 225

Example of Drawing. 226

Creating an isigraph Graphics Control 226

Selecting an isigraph Control for Output 227

Addressing the Screen. 227

Drawing Graphics. 227

Drawing Text 227

The Drawing Surface. 228

Screen Resizing: The paint Event 228

Partial List of glxxx Drawing Commands. 228

isigraph Events. 231

High Performance: Blocks of glxxx Commands Using glcmds.. 231

Displaying Tabular Data: the Grid Control 232

3D Graphics: OpenGL.. 232

34. Odds And Ends. 233

Startup and Configuration. 233

Public Names. 234

Seeing What Scripts Have Been Loaded. 235

Dyad # Revisited. 235

Boxed words to string: Monad ;:^:_1.. 236

Spread: #^:_1.. 236

Choose From Lists Item-By-Item: monad m}.. 236

Recursion with $: and Memoization with M... 236

Make a Table: Adverb dyad u/.. 237

Cartesian Product: Monad {.. 238

Boolean Functions: Dyad m b... 239

Functions on Boolean operands. 239

Bitwise Boolean Operations on Integers and Characters. 239

Operations Inside Boxes: u L: n, u S: n.. 240

Comparison Tolerance !.f.. 242

Right Shift: Monad |.!.f.. 243

Generalized Transpose: Dyad |:.. 243

Monad i: and Dyad i:.. 244

Fast String Searching: s: (Symbols) 244

Fast Searching: m&i... 246

CRC Calculation. 246

Unicode Characters: u:.. 246

Window Driver And Form Editor 246

35. Performance: Measurement & Tips. 247

Timing Individual Sentences. 247

Use Large Verb-Ranks! and Integrated Rank Support 249

Tips For Coding. 250

Avoid Boxing, Especially Small Boxes. 251

Use the Dyad i. Family: Dyad i. i: e. -., Monad ~. ~: u/... 251

Use u&.> (u each) To Operate Inside Boxes. 251

Use In-Place Assignment 251

Use Compounds Recognized by the Interpreter 251

Shining a Light: The J Performance Monitor 253

Tacit Programming  255

36. Tacit Programs. 256

37. Introduction to Forks. 258

38. Parsing and Execution I. 260

Definitions That Refer To x or y.. 262

39. Parsing and Execution II. 263

The Parsing Table. 263

Examples Of Parsing And Execution. 265

Undefined Words. 268

40. Forks, Hooks, and Compound Adverbs. 270

Tacit and Compound Adverbs. 273

Referring To a Noun In a Tacit Verb. 274

41. Readable Tacit Definitions. 275

Flatten a Verb: Adverb f... 275

Using f. to improve performance. 276

42. Explicit-To-Tacit Converter 278

Assignments in 13 : Tacit Definitions. 279

Special Verb-Forms Used in Tacit Definitions. 279

43. Common Mistakes. 280

Mechanics. 280

Programming Errors. 281

44. Valedictory. 284

45. Glossary. 285

46. Error Messages. 289

47. Index. 292

 



>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  J for C Programmers