0% found this document useful (0 votes)
33 views77 pages

J For C Programmers Henry Rich Instant Download

The document is a guide for experienced C programmers looking to learn the J programming language, highlighting the differences in syntax and programming paradigms. It emphasizes the productivity and efficiency of J compared to C, while acknowledging the challenges of transitioning from C to J. The book aims to provide a foundational understanding of J using familiar concepts from C programming.

Uploaded by

xdojffyhu620
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views77 pages

J For C Programmers Henry Rich Instant Download

The document is a guide for experienced C programmers looking to learn the J programming language, highlighting the differences in syntax and programming paradigms. It emphasizes the productivity and efficiency of J compared to C, while acknowledging the challenges of transitioning from C to J. The book aims to provide a foundational understanding of J using familiar concepts from C programming.

Uploaded by

xdojffyhu620
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

J For C Programmers Henry Rich download

https://ebookbell.com/product/j-for-c-programmers-henry-
rich-1054122

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

C For Programmers With An Introduction To C11 C11 2016th Edition Paul


J Deitel

https://ebookbell.com/product/c-for-programmers-with-an-introduction-
to-c11-c11-2016th-edition-paul-j-deitel-67733738

C For Programmers Contains 240 Examples Deitel Harvey M Deitel

https://ebookbell.com/product/c-for-programmers-contains-240-examples-
deitel-harvey-m-deitel-21999956

C 2010 For Programmers 4th Edition Deitel Developer Series 4th Edition
Paul J Deitel

https://ebookbell.com/product/c-2010-for-programmers-4th-edition-
deitel-developer-series-4th-edition-paul-j-deitel-2011594

C11 For Programmers Paul J Deitel Harvey M Deitel

https://ebookbell.com/product/c11-for-programmers-paul-j-deitel-
harvey-m-deitel-37011420
C11 For Programmers 2nd Edition Paul J Deitel Harvey M Deitel

https://ebookbell.com/product/c11-for-programmers-2nd-edition-paul-j-
deitel-harvey-m-deitel-4658286

C11 For Programmers Paul J Deitel Paul J Harvey M Deitel

https://ebookbell.com/product/c11-for-programmers-paul-j-deitel-paul-
j-harvey-m-deitel-35996122

C 2012 For Programmers 5th Edition Deitel Developer Series Paul J


Deitel Harvey M Deitel

https://ebookbell.com/product/c-2012-for-programmers-5th-edition-
deitel-developer-series-paul-j-deitel-harvey-m-deitel-80211462

C11 For Programmers C112 2016th Edition Paul J Deitel

https://ebookbell.com/product/c11-for-programmers-c112-2016th-edition-
paul-j-deitel-231608280

Tcpip Sockets In C Practical Guide For Programmers 2nd Edition Michael


J Donahoo Kenneth L Calvert

https://ebookbell.com/product/tcpip-sockets-in-c-practical-guide-for-
programmers-2nd-edition-michael-j-donahoo-kenneth-l-calvert-33554962
J
For C Programmers
Henry Rich
2006/01/25 (J6.01)
Copyright © 2004 Henry H. Rich. All rights reserved.
Send comments to HenryHRich@nc.rr.com
Foreword
You are an experienced C programmer who has heard about J, and you think you'd
like to see what it's all about. Congratulations! You have made a decision that will
change your programming life, if only you see it through. The purpose of this book is to
help you do that.
It won't be easy, and it certainly won't be what you're expecting. You've learned
languages before, and you know the drill: find out how variables are declared, learn the
syntax for conditionals and loops, learn how to call a function, get a couple of examples
to edit, and you're a coder. Fuggeddaboutit! In J, there are no declarations, seldom will
you see a loop, and conditionals often go incognito. As for coding from examples, well,
most of our examples are only a couple of lines of code—you won't get much momentum
from that! You're just going to have to grit your teeth and learn a completely new way to
write programs.
Why should you bother? To begin with, for the productivity. J programs are usually
a fifth to a tenth as long as corresponding C programs, and along with that economy of
expression comes coding speed. Next, for the programming environment: J is an
interpreted language, so your programs will never crash, you can modify code while it's
running, you don't have to deal with makefiles and linking, and you can test your code
simply by entering it at the keyboard and seeing what it does.
If you stick with it, J won't just help the way you code, it'll help the way you think. C
is a computer language; it lets you control the things the computer does. J is a language
of computation: it lets you describe what needs to be done without getting bogged down
in details (but in those details, the efficiency of its algorithms is extraordinary). Because
J expressions deal with large blocks of data, you will stop thinking of individual numbers
and start thinking at a larger scale. Confronted with a problem, you will immediately
break it down into pieces of the proper size and express the solution in J—and if you can
express the problem, you have a J program, and your problem is solved.
Unfortunately, it seems to be the case that the more experience you have as a C
programmer, the less likely you are to switch to J. This may not be because prolonged
exposure to C code limits your vision and contracts the scope of your thinking to the size
of a 32-bit word—though studies to check that are still under way and it might be wise
for you to stop before it's too late—but because the better you are at C, the more you have
to lose by switching to J. You have developed a number of coding habits: for example,
how to manage loops to avoid errors at extreme cases; how to manage pointers
effectively; how to use type-checking to avoid errors. None of that will be applicable to
J. J will take advantage of your skill in grasping the essence of a problem—indeed, it
will develop that skill considerably by making it easier for you to express what you
grasp—but you will go through a period during which it will seem like it takes forever to
get things done.
During that period, please remember that to justify your choice of J, you don't have to
be as expert in J as you were in C; you only have to be more productive in J than you

ii
were in C. That might well happen within a month. After you have fully learned J, it
will usually be your first choice for describing a program.
Becoming a J programmer doesn't mean you'll have to give up C completely; every
language has its place. In the cases where you want to write code in C (either to use a
library you have in C or to write a DLL for a function that is inefficiently computed in J),
you will find interfacing J to DLLs to be simple and effective.
This book's goal is to explain rudimentary J using language familiar to a C
programmer. After you finish reading it, you should do yourself the honor of carefully
reading the J Dictionary, in which you can learn the full language, one of the great
creations in computer science and mathematics.

Acknowledgements
I am obliged to the reviewers who commented on earlier versions: Michel Dumontier,
Ken Iverson, Fraser Jackson, David Ness, Richard Payne, Ewart Shaw, and Keith Smillie.
Brian Schott, Nicholas Spies, and Norman Thomson exchanged emails with me at length
to smooth over rough spots. David Steele conducted a painstaking review of several
early drafts and suggested many changes great and small. Björn Helgason translated the
text into Icelandic, finding a number of errors along the way. Kip Murray's 'review'
became more of a dismantling, cleaning, and reassembly operation in which large
sections of prose were rewritten as he pointed out to me their essential meaninglessness;
the reader should be as grateful to him as I am.
Without the patient explanations of my early teachers in J, Raul Miller and Martin
Neitzel, I would have given up on J. I hope that this book pays to others the debt I owe to
them.
My current happy career as a J programmer would not have been possible without the
work of the staff at Jsoftware, Inc., who created J. For the patriarch, the late Ken Iverson,
I am unworthy to express admiration: I have only awe. I hope his achievement eases the
lives of programmers for generations to come. To the rest, both Iversons and non-
Iversons, I give my thanks.
The implementation of the J interpreter has required diverse skills: architectural
vision, careful selection of algorithms, cold-eyed project management to select features
for implementation, robust and efficient coding, performance optimization, and expertise
in numerical analysis. Most improbably, all these talents have resided in one man, Roger
Hui il miglior fabbro. J gives us all a way to have a little of Roger's code in our own.
We should aspire no higher.

Change History
2002/6/18: Add chapters on mathematics in J, and section on Symbols; minor changes to
wording; bring text up to J Release 5.01
2002/8/16: Minor additions; added section on aliasing; added chapter on sockets
2002/9/26: Added sections on fndisplay, integrated rank support, and ordering of implied
loops

iii
2002/11/14 Added explanatory sections, section on the J Performance Monitor, and
chapter on Error Messages
2003/07/18 (J5.03) added section on I., updated f. . Added chapter on frequent errors.
Added section on run-length decoding
2004/10/31 (J5.04) ^:a:, vector cut. Added chapter on Sequential Machines
2004/11/22 Added section on monad {
2005/04/14 Fixed discussion of throw.
2005/09/03 (J6.01) added chapter on Graphics, discussion of noun forks, section on Fast
Searching, section on CRC. Switched chapters 10 & 11, and added pictorial
discussion of @ and @: . Added example on partitions. Added section on 3!:4 5
conversions. Explained the difference between (number number) and (noun noun).
2005/01/25 Account for 6.01 changes. Describe dyad I.

iv
Contents
Foreword ............................................................................................................................. ii
Acknowledgements.................................................................................................. iii
Change History ........................................................................................................ iii
1. Introduction................................................................................................................... 1
2. Culture Shock................................................................................................................ 2

Programming In J 5
3. Preliminaries ................................................................................................................. 6
Notation Used in This Book ..................................................................................... 6
Terminology.............................................................................................................. 6
Sentences (statements) ........................................................................................... 7
Word Formation (tokenizing rules) ........................................................................ 7
Numbers.................................................................................................................... 8
Adjacent Numbers Form a Single Word .............................................................. 8
Adjacent Named Nouns Do NOT Form a Single Word....................................... 9
Characters ................................................................................................................. 9
Valence of Verbs (Binary and Unary Operators) ................................................. 9
How Names (Identifiers) Get Assigned................................................................. 10
Order of Evaluation ................................................................................................ 10
How Names Are Substituted................................................................................... 11
What a verb (function) looks like........................................................................... 12
Running a J program............................................................................................... 13
Interrupting Execution........................................................................................ 14
Errors .................................................................................................................. 14
The Execution Window; Script Windows .............................................................. 14
Names Defined at Startup ....................................................................................... 15
Step-By-Step Learning: Labs.................................................................................. 15
J Documentation ..................................................................................................... 16
Getting Help............................................................................................................ 16
4. A First Look At J Programs ........................................................................................ 17
Average Daily Balance ........................................................................................... 17
Calculating Chebyshev Coefficients....................................................................... 20
5. Declarations ................................................................................................................ 22
Arrays...................................................................................................................... 22
Cells ........................................................................................................................ 23
Choosing Axis Order.......................................................................................... 24
Negative Cell-Rank; Items ................................................................................. 24
Lists .................................................................................................................... 24
Phrases To Memorize ............................................................................................. 25
Constant Lists ......................................................................................................... 25
Array-creating Verbs .............................................................................................. 25
Dyad $ ($hape) and monad $ ($hape Of) .......................................................... 25

v
Monad # (Tally) ................................................................................................. 30
Monad i. (Integers) .......................................................................................... 30
6. Loopless Code I—Verbs Have Rank.......................................................................... 32
Examples of Implicit Loops.................................................................................... 32
The Concept of Verb Rank ..................................................................................... 34
Verb Execution—How Rank Is Used (Monads) .................................................... 34
Controlling Verb Execution By Specifying a Rank................................................ 36
Examples Of Verb Rank ......................................................................................... 37
fndisplay—A Utility for Understanding Evaluation ........................................ 40
Negative Verb Rank................................................................................................ 41
Verb Execution—How Rank Is Used (Dyads) ....................................................... 42
Concatenating Lists: Dyad , (Append).............................................................. 44
When Dyad Frames Differ: Operand Agreement ................................................... 45
Order of Execution in Implied Loops ..................................................................... 49
A Mistake To Avoid ............................................................................................... 49
7. Starting To Write In J ................................................................................................. 51
8. More Verbs ................................................................................................................. 54
Arithmetic Dyads.................................................................................................... 54
Boolean Dyads........................................................................................................ 55
Min and Max Dyads ............................................................................................... 55
Arithmetic Monads ................................................................................................. 55
Boolean Monad....................................................................................................... 55
Operations on Arrays .............................................................................................. 56
Dyads.................................................................................................................. 56
Monads ............................................................................................................... 62
9. Loopless Code II—Adverbs / and ~.......................................................................... 66
Modifiers................................................................................................................. 66
The Adverb Monad u/ ........................................................................................... 66
The adverb ~ ........................................................................................................... 68
10. Continuing to Write in J.............................................................................................. 70
11. Boxing (structures).................................................................................................... 76
Terminology............................................................................................................ 78
Boxing As an Equivalent For Structures In C ...................................................... 79
12. Compound Verbs ........................................................................................................ 80
Verb Sequences—u@:v and u@v .......................................................................... 80
The Difference Between u@:v and u@v ........................................................... 81
An Exercise in @ and @: .................................................................................... 82
Making a Monad Into a Dyad: The Verbs [ and ]................................................... 84
Making a Dyad Into a Monad: u&n and m&v......................................................... 85
13. Empty Operands.......................................................................................................... 87
Execution On a Cell Of Fills................................................................................... 87
Empty cells ............................................................................................................. 89
If Fill-Cells Are Not Enough .................................................................................. 89
14. Loopless Code III—Adverbs \ and \. ....................................................................... 90
15. Verbs for Arithmetic ................................................................................................... 93
Dyads ...................................................................................................................... 93

vi
Monads (all rank 0)................................................................................................. 94
16. Loopless Code IV ....................................................................................................... 95
A Few J Tricks........................................................................................................ 95
Power/If/DoWhile Conjunction u^:n and u^:v ................................................ 96
Tie and Agenda (switch) ........................................................................................ 99
The Tie Conjunction u`v u`n m`v m`n...................................................... 99
The Agenda (switch) conjunction m@.v ......................................................... 100
17. More Verbs For Boxes.............................................................................................. 101
Dyad ; (Link) And Monad ; (Raze).................................................................... 101
Dyad , Revisited—the Case of Dissimilar Items ............................................ 103
Verbs With More Than 2 Operands—Multiple Assignment ........................... 103
Dyad { Revisited: the Full Story .......................................................................... 104
Simplification 1: Remove Inner Boxing If Selectors Are Scalars.................... 106
Simplification 2: Remove All Boxing To Select Full Items ............................ 106
Split String Into J Words: Monad ;: ................................................................... 107
Fetch From Structure: Dyad {:: ......................................................................... 107
Report Boxing Level: Monad L. ......................................................................... 108
18. Verb-Definition Revisited......................................................................................... 110
What really happens during m :n and verb define ..................................... 110
Compound Verbs Can Be Assigned ..................................................................... 111
Dual-Valence verbs: u :v................................................................................... 112
The Suicide Verb [: ............................................................................................ 112
Multi-Line Comments Using 0 :0 ..................................................................... 113
Final Reminder ..................................................................................................... 113
19. u^:_1, u&.v, u&.:v, and u :.v ........................................................................ 114
The Obverse u^:_1............................................................................................. 114
Apply Under Transformation: u&.v and u&.:v ................................................ 114
Defined obverses: u :.v .................................................................................... 116
u&:v and u&v ................................................................................................... 116
An observation about dyadic verbs....................................................................... 117
20. Performance: Measurement & Tips .......................................................................... 118
Timing Individual Sentences ................................................................................ 118
Compounds Recognized by the Interpreter .......................................................... 120
Use Large Verb-Ranks! and Integrated Rank Support ......................................... 121
Shining a Light: The J Performance Monitor ....................................................... 122
21. Input And Output ...................................................................................................... 125
Foreigns ................................................................................................................ 125
File Operations 1!:n; Error Handling................................................................. 125
Error Handling: u ::v, 13!:11, and 9!:8................................................. 126
Treating a File as a Noun: Mapped Files.............................................................. 126
Format Data For Printing: Monad And Dyad ": ................................................. 127
Monad ": ......................................................................................................... 128
Format an Array: 8!:n ........................................................................................ 129
Format binary data: 3!:n .................................................................................... 130
printf, sprintf, and qprintf.................................................................... 131

vii
Convert Character To Numeric: Dyad ". ............................................................ 131
22. Calling a DLL Under Windows................................................................................ 133
Memory Management........................................................................................... 134
Filling a Structure: Conversions....................................................................... 135
Aliasing of Variables ............................................................................................ 135
Aliasing of Mapped Nouns............................................................................... 136
Aliasing of DLL Operands ............................................................................... 136
23. Socket Programming................................................................................................. 138
sdselect ........................................................................................................... 138
Asynchronous Sockets and socket_handler ................................................ 138
Names and IP Addresses....................................................................................... 139
Connecting ............................................................................................................ 140
Listening ............................................................................................................... 140
Other Socket Verbs............................................................................................... 141
Datagrams......................................................................................................... 141
Socket Options.................................................................................................. 141
Housekeeping ................................................................................................... 142
24. Loopless Code V—Partitions ................................................................................... 143
Find Unique Items: Monad ~. and Monad ~: .................................................... 143
Apply On Subsets: Dyad u/. .............................................................................. 143
Apply On Partitions: Monad u;.1 and u;.2..................................................... 145
Apply On Specified Partitions: Dyad u;.1 and u;.2 ...................................... 146
Find Sequence Of Items: Dyad E.................................................................... 147
Multidimensional Partitions ............................................................................. 148
Apply On Subarray: Dyad u;.0.......................................................................... 148
Apply On All Subarrays: Dyad u;.3 and u;._3 .............................................. 149
Extracting Variable-Length Fields Using ^: and ;.1 ........................................ 150
Example: Combining Adjacent Boxes.................................................................. 151
25. When Programs Are Data ......................................................................................... 153
Calling a Published Name..................................................................................... 153
Using the Argument To a Modifier ...................................................................... 153
Invoking a Gerund: m`:6..................................................................................... 154
Passing the Definition Of a Verb: 128!:2 (Apply)............................................ 155
Passing an Executable Sentence: Monad ". and 5!:5....................................... 156
26. Loopless Code VI ..................................................................................................... 157
27. Loopless Code VII—Sequential Machines............................................................... 161
28. Modifying an array: m}............................................................................................. 164
Monad I.—Indexes of the 1s in a Boolean Vector ............................................. 165
Modification In Place............................................................................................ 166
29. Control Structures ..................................................................................................... 167
for./do./end. and for_x./do./end.......................................................... 167
while./do./end. and whilst./do./end. ................................................. 167
if./do./else./end., if./do./elseif./do./end.................................. 167
try./catch./catcht./end. and throw. ................................................. 168
select./case./fcase./end. ...................................................................... 168

viii
return............................................................................................................... 169
assert............................................................................................................... 169
30. Modular Code ........................................................................................................... 170
Locales And Locatives.......................................................................................... 170
Assignment ........................................................................................................... 170
Name Lookup ....................................................................................................... 171
Changing The Current Locale............................................................................... 172
The Shared Locale 'z' ........................................................................................ 175
Using Locales ....................................................................................................... 175
31. Writing Your Own Modifiers ................................................................................... 177
Modifiers That Do Not Refer To x. Or y. ......................................................... 177
Example: Creating an Operating-System-Dependent Verb ............................. 178
Example: The LoopWithInitial Conjunction ........................................ 179
Example: A Conjunction that Analyzes u and v.............................................. 179
An Exception: Modifiers that Do Not Refer to u. or v. ................................ 181
Modifiers That Refer To x. Or y. ...................................................................... 181
32. Applied Mathematics in J ......................................................................................... 184
Complex Numbers ................................................................................................ 184
Matrix Operations ................................................................................................. 184
Polynomials: p..................................................................................................... 185
Calculus: d., D., D:, and p.. ............................................................................ 186
Taylor Series: t., t:, and T............................................................................... 187
Hypergeometric Function with H. ....................................................................... 187
Sparse Arrays: Monad and Dyad $. .................................................................... 188
Random Numbers: ?............................................................................................. 188
Computational Addons ......................................................................................... 189
Useful Scripts Supplied With J............................................................................. 189
33. Elementary Mathematics in J.................................................................................... 190
Verbs for Mathematics.......................................................................................... 190
Extended Integers, Rational Numbers, and x:..................................................... 190
Factors and Primes: Monad p:, Monad and Dyad q: ......................................... 191
Permutations: A. and C....................................................................................... 191
34. Graphics .................................................................................................................... 193
Plot Package.......................................................................................................... 193
Plot Demo......................................................................................................... 193
Interfaces to Plot............................................................................................... 193
Commands and Options ................................................................................... 194
Data; Constructing a Plot with pd.................................................................... 195
Quick Plots Using plot .................................................................................. 196
Generating Plots of Functions .......................................................................... 197
Assembling a Multipart Plot with pd............................................................... 198
Examples of Plots with Multiple Sets of Points ............................................... 199
Plots of Parametric Functions........................................................................... 199
Output Options ................................................................................................. 199
2D Graphics: the gl2 Library ................................................................................ 199

ix
Example of Drawing......................................................................................... 200
Creating an isigraph Graphics Control....................................................... 200
Selecting an isigraph Control for Output ................................................... 201
Addressing the Screen ...................................................................................... 201
Drawing Graphics............................................................................................. 201
Drawing Text.................................................................................................... 201
The Drawing Surface........................................................................................ 202
Screen Resizing: The paint Event................................................................. 202
Partial List of glxxx Drawing Commands ..................................................... 202
isigraph Events ........................................................................................... 205
High Performance: Blocks of glxxx Commands Using glcmds ................. 205
Displaying Tabular Data: the Grid Control .......................................................... 206
3D Graphics: OpenGL .......................................................................................... 206
35. Odds And Ends ......................................................................................................... 207
Dyad # Revisited .................................................................................................. 207
Boxed words to string: Monad ;:^:_1 .............................................................. 207
Spread: #^:_1 ..................................................................................................... 207
Choose From Lists Item-By-Item: monad m} ...................................................... 207
Recursion: $: ....................................................................................................... 208
Make a Table: Adverb dyad u/............................................................................ 208
Cartesian Product: Monad { ................................................................................. 209
Boolean Functions: Dyad m b. ........................................................................... 210
Functions on Boolean operands........................................................................ 210
Bitwise Boolean Operations on Integers .......................................................... 210
Operations Inside Boxes: u L: n, u S: n ...................................................... 211
Comparison Tolerance !.f.................................................................................. 213
Right Shift: Monad |.!.f .................................................................................. 213
Generalized Transpose: Dyad |: ......................................................................... 214
Monad i: and Dyad i: ....................................................................................... 214
Fast String Searching: s: (Symbols) ................................................................... 215
Fast Searching: m&i. ........................................................................................... 216
CRC Calculation ................................................................................................... 216
Unicode Characters: u:........................................................................................ 216
Window Driver And Form Editor......................................................................... 216

Tacit Programming 217


36. Tacit Programs .......................................................................................................... 218
37. First Look At Forks................................................................................................... 220
38. Parsing and Execution I ............................................................................................ 222
39. Parsing and Execution II........................................................................................... 225
The Parsing Table ................................................................................................. 225
Examples Of Parsing And Execution ................................................................... 226
Undefined Words.................................................................................................. 230
40. Forks, Hooks, and Compound Adverbs.................................................................... 231
Tacit and Compound Adverbs .............................................................................. 234

x
Referring To a Noun In a Tacit Verb.................................................................... 235
41. Readable Tacit Definitions ....................................................................................... 236
Flatten a Verb: Adverb f..................................................................................... 236
Using f. to improve performance ................................................................... 237
42. Explicit-To-Tacit Converter...................................................................................... 239
Special Verb-Forms Used in Tacit Definitions..................................................... 240
43. Common Mistakes .................................................................................................... 241
Mechanics ............................................................................................................. 241
Programming Errors ............................................................................................. 242
44. Valedictory................................................................................................................ 245
45. Glossary .................................................................................................................... 246
46. Error Messages.......................................................................................................... 250
47. Index ......................................................................................................................... 252

xi
1. Introduction
This book will tell you enough about J for you to use it as a language for developing
serious applications, but it is about more than learning the J language: it is also about
'thinking big' in programming, and how programming in J is fundamentally different
from programming in C. C programs deal intimately with scalars (single numbers and
characters), and even when they combine those scalars into arrays and structures, the
operations on the arrays and structures are defined by operations on the scalars. To
ensure that each item of an array is operated on, loops are created that visit each element
of the array and perform a scalar operation on the element.
Writing code in a scalar language makes you rather like a general who gives orders to
his troops by visiting each one and whispering in his ear. That touch-of-Harry kind of
generalling can achieve victorious results, and it has the advantage that the orders can be
tailored to the man, but its disadvantages are significant: the general spends much mental
energy in formulating individual orders and much breath in communicating them
individually; more significant, his limited attention is drawn toward individuals and away
from the army as a whole. Even the great Rommel was overtaxed at times.
The J programmer is, in contrast, a general who stands before his army and snaps out
orders to the army as a whole. Every man receives the same order, but the order itself
contains enough detail for the individual men to act appropriately. Such a general can
command a corps as easily as a platoon, and always has the 'big picture' in mind.
OK, maybe you're not Rommel, but you are a working programmer, and you suspect
that very few practical programs can be represented as array operations—matrix
multiplication maybe, or adding a list of numbers—and that, even if a wide range of
programs were possible, the set of operations supported must be too vast to be practical:
wouldn't we need an array operation for every possible program?
The first half of this book is devoted to showing you that it is indeed possible to write
meaningful programs with array operations. We take the approach of looking at the
different ways loops are used, and seeing what facilities J has for producing the same
result using array operations. We will find that J contains a couple of dozen array-
processing primitives and a dozen or so very cleverly chosen pipe-fittings that allow
those primitives to be connected together to provide the limitless supply of array-
processing functions needed for practical programming.
Interspersed with the elaboration of more and more intricate array operations are
treatments of other matters of use in practical programming: structure definition, input
and output, performance measurement, calling DLLs, modular programming. Eventually
we will see how to use if-then-else and do-while in J, though you will have learned more
elegant ways to get the same results.
The last portion of the book is devoted to the optional topic of tacit programming, J's
language for functional programming. Tacit programming is an extremely terse way of
expressing algorithms, one that allows programs that have been compressed from a page
of C into a few lines of J to be compressed still further.

1
2. Culture Shock

A C Programmer's First Thoughts On J


This doesn't look like a program. Where did the program go?
You have gotten used to the pace and structure of C. You can recognize a loop, you
figure out what the loop is doing, you see what variables it sets. The assignments and the
loops are signposts that direct your analysis of code.
In J, every operator has a loop built in, so they don't jump out at you in the same way.
And because the syntax of J is so terse, and arrays use the same syntax as single
variables, there is much less need for temporary variables.
Here's an example. Figure out what the following code does:

int i, j, maxcol = 0;
float maxval = x[0][0];
for(i = 0;i<=xsize0;++i) {
for(j = 0;j<=xsize1;++j) {
if(x[i][j] > maxval) {
maxval = x[i][j];
maxcol = j;
}
}
}

Not too hard. When the code finishes, maxval is the largest element in the array x,
and maxcol is the column number it was in. As it happens, all I wanted was the column
number, but there was no way for you to know that.
The same code in J:

maxcol =. (i. >./) >./ x


With some practice, you will learn to read this code just as easily as you read the C.
You will recognize the / as an indicator of a loop, and the i. as an indicator for a search.

What happened to the if statement?


It's built into the >. primitive. Just as most loops are hidden inside primitives, so are
most conditionals. The functions you write can also contain built-in conditionals.

What's the statement delimiter?


There isn't one. Statements are exactly one line long.

2
I've looked at some J code. Every other character is a period or a colon. I've got spots
before my eyes. How can anybody read this stuff?
You'll get used to it. J has a great many primitives, and it's important to keep the
names short so that you can fit a lot of computation on one line; so the names are either
single characters, like >, or a character with a period or space appended (>. and >:).
The period/colon is just part of the name. Single letters with period/colon, like i., are
also used for primitives. If you want to assign your own names to the primitives, you are
allowed to, but pretty soon you'll want to go back to the shorter names to save space and
typing.

Where are the declarations? Doesn't J use arrays? How do I know what the type of a
variable is?
Oh yeah, J uses arrays. Any variable can be an array. As for what the type and
dimensioning is: you assigned the variable, didn't you? It contains whatever you put into
it, a number, a string, an array, a structure... J will remember. If your program logic
requires you to find out the current attributes of a variable, J can tell you.
Every J program, both primitives and programs that you write, can automatically be
applied to arrays. The carefully-thought-out way this is done is one of the prime
strengths of J. The statement
x + y
means 'add x to y'; it will do that if x and y are single numbers, or if they are
multidimensional arrays. The looping needed to operate on the individual numbers is
built into the language, not into your program.

I've looked at a line of J code and it's just a mess with no discernible syntax.
Something like
lifodd =. ]`[@.(2&|@[)
perhaps, a program that returns the left operand if it is odd, otherwise the right operand?
Patience. Every character has a meaning, even the ` " [ ] { } characters which act
individually, not as pairs. Learn what they mean and all will become clear.

I ran across this line: 1 2 + 3. What's with the extra number floating in space?
1 2 is a one-dimensional array of 2 numbers with the values 1 and 2. Arrays come
up so much in J that we use this shorthand to define one without requiring any more
syntax than just the values of the elements of the array.

I've looked at a line of J code and I'm absolutely sure there are no variables in it at all.
How can that mean anything?
Oh, you've stumbled onto a tacit program, which describes its computation without
referring to any variables, not even symbolic parameters. The classic teaching example is
mean =: +/ % #
which the mean of an array of numbers. Tacit programs are considered an advanced
topic in this book, and are covered in a section at the end. They are the ultimate in

3
concise expression; many J programmers favor them for that reason, but you can wait to
learn about them until you've learned simple J.

In the examples all I see are things that contain =:, which I'm guessing are
assignment statements. How do I write a program?
Some of the assignment statements are programs. In J, a name becomes a function
name when you assign it a value that is a function.

Once I've written a program, how do I run it? I don't see anything that looks like a
function call.
In J, there is no special syntax for a function call. Just as you perform the 'minus'
function with - y or the 'subtract' function with x - y, you invoke a user-defined
function by typing its name before or between its operands:
x DifferenceSquared y or FindPrimeGreaterThan 1000.

How do I compile my program?


You don't. J is interpreted. As soon as you type your program in (or read it in from a
file), it's ready to use. Here's a starter program:
h =: verb : '''Hello world.'''
Type that (note the triple quotes), then run it with
h ''

The triple quotes are ugly.


Quit bellyaching. Read the book and you'll learn how to avoid them. Remember
those 10 lines of C that were replaced by a quarter-line of J, and learn how to do that
yourself.

4
Programming In J

5
3. Preliminaries

Notation Used in This Book


C code is set in Arial font, like this: for(I = 0;I<10;I++)p[I] = q;
J code is set in Courier New font, like this: p =. 10 $ q
When J and C use different words for the same idea, the J word is used. The first few
times, the C word may be given in parentheses, in Arial font: verb (function). When a
word is given a formal definition, it is set in bold italics: verb.

Terminology
To describe the elements of programming, J uses a vocabulary that will be familiar,
though possibly frightening: the vocabulary of English grammar. We will speak of
nouns, verbs, and the like. Don't worry, you're not going to have to write a book report!
Use of this terminology is not as strange as it may seem. Take 'verb', for example, an
idea that corresponds to the C 'function' or 'operator'. Why not just say 'operator'?
Well, that word is also used in mathematics and physics, with a meaning quite different
from C's. Even a C 'function' is not a true mathematical function—it can return different
values after invocations with the same arguments.
J avoids imprecise usage by choosing a familiar set of words and giving them entirely
new meanings. Since J is a language, the vocabulary chosen is that of English grammar.
It is hoped that the familiarity of the words will provide some mnemonic value, but as
long as you learn the J meanings you are free to forget the grammatical ones. The
following table may help:
J word C word
verb function or operator
noun object
copula assignment
punctuation separator
adverb (#define macro)
conjunction (#define macro)
In keeping with the grammatical flavor of the vocabulary, we say that every word
(token) in a J program has a part of speech (name type) which is one of the following:
noun, verb, adverb, adjective, copula, or punctuation.
The primary parts of speech are noun, verb, adverb, and conjunction. Every name
we can create, and every word defined by J except for the copulas (=. and =:) and
punctuation, will be a definite one of the primary parts of speech. In this book, the term
entity is used to mean something that can be any of the primary parts of speech. An

6
entity can be assigned to a name, but most entities are anonymous, appearing and
disappearing during the execution of a single sentence (just like intermediate results in
the evaluation of C expressions).
A noun holds data; a verb operates on one or two nouns to produce a result which is a
noun; an adverb operates on one noun or verb to produce a derived entity; a conjunction
operates on two nouns or verbs to produce a derived entity. Adverbs and conjunctions
are called modifiers. The closest thing C has to a modifier is a preprocessor macro which
can accept function names as data and produce code sequences including the name. J
modifiers perform their actions during execution rather than compilation, providing
opportunities unknown to C.
A word on punctuation under J's definition: it consists of the characters ( ) ' and
end-of-line (written LF but representing either a single LF character or the CRLF
combination), along with the comment delimiter NB. and a few other special words like
if. and case. . There are a lot of other characters that you think of as punctuation,
namely [ ] , . " ; { }, that J uses to do work. You will be especially surprised
to find that [ ] and { } are independent rather than matched pairs, but you'll get used
to it.

Sentences (statements)
The executable unit in J is called the sentence, corresponding to the C statement.
The sentence delimiters in J (corresponding to the semicolon in C) are the linefeed LF
and the control words like if. that we will learn about later. A sentence comprises all
the characters between sentence delimiters; since LF is a sentence delimiter, it follows
that a J sentence must all fit on one line. There is nothing corresponding to \<CR> in C
that allows you to split a sentence across lines.
All comments start with NB. and run to the next LF . The comment is ignored when
the sentence is executed.

Word Formation (tokenizing rules)


J's names (identifiers) are formed much as in C. Names must begin with an
alphabetic, underscore is allowed, and upper- and lowercase letters are distinguished.
Names that end with an underscore or contain two consecutive underscores are special,
and you should avoid them until you know what a locale is.
The ASCII graphic characters ('+', for example) are called primitives (operators) in
J. You will learn their meanings as we go on.
Any name or primitive (identifier or operator) can be made into a new primitive by
adding '.' or ':' at the end. Since all primitives are system-defined (i. e. they are
reserved words), you may not put '.' or ':' in your names. No space is required after a
primitive. The part of speech for each primitive is fixed. Example primitives are:

7
+ +. +: { {: {:: i. i: for. select. case. end.
The first step in processing a sentence is to split it into words. The words correspond
roughly to C tokens, after making allowance for the special status of the '.' and ':'
characters. The space and TAB characters are treated as whitespace.
We will be careful to distinguish periods used for English punctuation from the dot
that may be at the end of a primitive. When a J word comes at the end of an English
sentence, we will be sure to leave a space before the period. For example, the verb for
Boolean Or is +., while the verb for addition is + .

Numbers
You do not need to trouble yourself with the distinction between integers, floats, and
complex numbers. If it's a number, J will handle it properly. There are a great many
ways to specify numbers; consult the Dictionary to learn details, including, among other
things, complex numbers, extended-precision integers, and exponential forms. Example
numbers are:
2
_2 (underscore, not -, is the negative sign)
0.5 (since '.' is special, it must not be the first character of a number)
1e2
16b1f (equivalent to 0x1f)
_ (infinity, which is a perfectly valid number in J)
__ (negative infinity, represented by two underscores)
A noun whose value is one of the numbers 0 and 1 is said to be Boolean. Many verbs
in J are designed to use or produce Boolean values, with 0 meaning false and 1 meaning
true, but there is no Boolean data type: any noun can be used as a Boolean if its values
are 0 or 1.
A word is in order in defense of the underscore as the negative sign. -x means 'take
the negative of the number x'; likewise -5 means 'take the negative of the number 5'. In
J, the number 'negative 5' is no cloistered companion, accessible only by reference to the
number 5: it is a number in its own right and it deserves its own symbol: _5.
Adjacent Numbers Form a Single Word
Numbers separated by whitespace are treated as a single word whose value is the list
of the numbers (we will learn all about lists soon—they're like arrays). Remember,
word formation is the first step in processing a sentence, so the numbers are welded into a
list before anything else can be done with them. This may cause you a problem if you
have adjacent numbers that should not be made into a list. In that case, put parentheses
around any number you want to keep separate.
You will quickly learn that lists of numbers are so common in J that creating them
automatically from adjacent numbers saves you a lot of typing.

8
Adjacent Named Nouns Do NOT Form a Single Word
Because the adjacent numbers 4 5 are turned into a list, you might think that a b,
when a and b have the values 4 and 5, would also be turned into a list. Not so. 4 5
becomes a list before any of the names are examined; at that point the interpreter does not
even know the part of speech of the names. a and b remain as separate words, to be
operated on as execution proceeds.

Characters
An ASCII string enclosed in single quotes is a constant of character type (examples:
'a', 'abc'). There is no notation to make the distinction between C's single-quoted
character constants and double-quoted character strings.
There are no special escape sequences such as '\n'. If you need a quote character
inside a string, double the quote: 'cannot can be shortened to can''t'.
Character constants do not include a trailing NUL (\0) character, and NUL is a legal
character within a string.

Valence of Verbs (Binary and Unary Operators)


C operators can be unary or binary depending on whether they have one or two
operands; for example, the unary * operator means pointer dereferencing (*p), while the
binary * operator means multiplication (x*y). J verbs also come in unary and binary
versions, with the addition that this applies to all verbs, both primitive and user-defined
verbs.
When a J verb (function or operator) is executed with only one operand (i. e.
without a noun or phrase that evaluates to a noun on its left) we say its invocation is
monadic (unary); if there is a noun or noun-phrase on its left, that noun becomes a
second operand to the verb and we say that the invocation is dyadic (binary). In the case
of programmer-defined verbs (functions), the versions handling the two cases are
defined independently. We use the term valence to describe the number of operands
expected by a verb-definition: a verb-definition has monadic valence if it can be applied
only monadically, dyadic valence if it can be applied only dyadically, and dual valence if
it can be applied either way. Since the definitions of the monadic and dyadic forms of a
verb can be wildly different, when we name a verb we will be careful to indicate which
version we are talking about: 'monad $', 'dyad i.'.
Note that it is impossible to invoke a verb with no operands. In C we can write
func(), but in J we always must give an operand.
Note also that the syntax of J limits verbs (functions) to at most two operands.
When you need a verb with more than two operands, you will represent it as a monad or
dyad in which one of the verb's syntactic operands is an aggregate of the actual operands
the verb will use during its execution. The first thing the verb will do is to split its
operand into the individual pieces. J has primitives to make this process easy.
The value produced by any entity when it is applied to its operand(s) is called its
result (returned value).

9
How Names (Identifiers) Get Assigned
Assignment in J is performed by expressions of the form
name =. entity NB. private
and
name =: entity NB. public
Names assigned by public assignment are visible outside the entity in which they are
defined; names assigned by private assignment usually are not; we will learn the details
when we discuss modular code. The difference between the two forms of assignment is
in the character following the = . Just as in C, the assignment expression is considered
to produce as its result the value that was assigned, so expressions like
a =. 1 + b =. 5
are legal. J calls =. and =: copulas. Just as in C, the entity that is assigned to the name
can be the result of evaluating an expression.
There are a number of additional capabilities of J assignment that you can read about
in the Dictionary. One that has no counterpart in C is that the name being assigned can
itself be a variable, i. e. you can calculate the name that you want to assign the value to.
The value assigned can be a noun (object), verb (function), adverb, or conjunction;
the name then becomes whatever part of speech was assigned to it (even if it was
previously defined as a different part of speech!). For example,
n =: 5
creates a noun, and
v =: verb define
x. + y.
)
creates a verb (more below).
Note: the J Dictionary uses the terms 'local' and 'global' instead of 'private' and
'public'. I think 'private' and 'public' are more accurate terms, because there is another
dimension to name scope in J, using the J notions locale and path, that causes public
variables to be visible only in certain entities. It will be a long time before we learn about
locales; until then, public names will be global.

Order of Evaluation
Forget the table of operator precedence! All J verbs (functions and operators)
have the same priority and associate right-to-left. For example, a * b + c is
equivalent to a * (b + c), not (a * b) + c. Use care when copying
mathematical formulas. Note that the negative sign _ is a part of the number, not a verb.
_5 + _4 is _9, while -5 + -4 is _1.
The executable bits of a sentence (statement) are called fragments
(subexpressions). A verb with its operand(s) is a fragment, as is a copula with its
name and value. We will meet other types of fragment later. Execution of a sentence
consists of the right-to-left execution of its fragments, with the result of each fragment's
execution replacing the fragment and being passed as an operand into the next fragment.
The result of the last execution becomes the result of the sentence. This result is usually

10
a noun but it can be any of the primary parts of speech. As an example, execution of the
sentence
a =. 3 + b =. 4 * 5
consists of execution of the following fragments: 4 * 5 with result 20; b =. 20 with
result 20; 3 + 20 with result 23; a =. 23 with result 23 . The names a and b are
assigned when the assignment fragments are executed.
If a verb has a noun on its left, it is executed as a dyadic verb with a left and right
operand. If the verb does not have a noun on its left, it is executed as monadic with just a
right operand. You must know the part of speech of the names in a sentence to
understand the execution order. In the sentence
result =. name1 verb2 5
you must know name1 is a verb, in which case verb2 is executed monadically and the
result is name1(verb2(5)), or name1 is a noun, in which case verb2 is dyadic and
the result is (name1 verb2 5) .

How Names Are Substituted


When a sentence contains names, the sentence is executed as if each name were
enclosed in parentheses and then replaced by its value. If a has the value 4 and b has
the value 5,
a + b
is equivalent to
(4) + (5)
Enclosing the value in parentheses is a necessary step to get the order of evaluation
right, just as in ordinary arithmetic, where if a is x+2 and b is y, ab is not x+2y, but
(x+2)y.
If you read the Dictionary you will soon encounter the example
mean=: +/ % #
mean 2 3 4 5 6
4
and you will probably follow in the footsteps of countless J neophytes, type into your J
session
+/ % # 2 3 4 5 6
0.2
and be baffled by the result. Why 0.2 instead of 4? Because you left out the
parentheses:
(+/ % #) 2 3 4 5 6
4
In this book, the discussion of what (+/ % #) means will be deferred for 200
pages, until the chapters on Tacit Programming. At that time it will also be revealed that
our notion of replacing a name with its parenthesized value is a simplification of the
actual process of execution. Forget that for now—you are highly unlikely to encounter a
situation where the simplification leads you into error.
Using the parenthesized-substitution rule, we can justify the difference between

11
4 5
and
a b
when a is 4 and b is 5 . 4 5 is two adjacent numbers, which are always treated as a
single word. a b is equivalent to (4) (5), which is not two adjacent numbers but
rather a syntax error.

What a verb (function) looks like


As we saw, a J verb (function) is defined by lines that look like:
name =: verb define
J sentences here
)
The result of the verb define is a verb, and normally you will assign the result to
a name so you can execute the verb by name when you need it. Subsequent lines, starting
with the one after verb define and ending before the next line containing only the
word ')', are read and saved as the text of the verb (heaven help you if you leave out
the )!). The verb is not 'compiled'—only the most rudimentary syntax checking is
performed; the text is saved and will be interpreted when the verb is executed.
Each line of the verb is a sentence (statement). The result of the last sentence
executed becomes the result of the whole verb (this is not precisely true but it's close
enough for now—details will be revealed in 'Control Structures').
Since a J verb has only one or two operands, there is no need for you to provide a list
of parameter names as you do in a function definition in C; instead, J names them for
you. At the start of a verb's execution, the private name y. is initialized with the value of
the right operand of the verb. If the verb is dyadic, the private name x. is initialized with
the value of the left operand. Many programmers like to start their verbs by assigning
these values to more descriptive names.
If your verb is going to define only a monadic or dyadic form, you should use
monad define or dyad define instead of verb define . If you are going to
define both valences, the way to do so is:
name =: verb define
monadic case here
:
dyadic case here
)
where a line with the single word : separates the two cases. If you use verb define
and don't have the :, the verb will be monadic.
If your verb is only one line long (not at all unusual in J!) you can define it all in one
line by using the appropriate one of the forms

12
name =: monad : 'text of verb'
name =: dyad : 'text of verb'

Running a J program
No compiling. No linking. No makefiles. No debugger. You simply type J
sentences and the interpreter executes them and displays any result. At the very simplest,
you can use it as a desk calculator:
22 + 55
77
J prints 3 spaces as a prompt, so when you scroll through the log of a session, your
input will be indented 3 spaces while J's typeout will be unindented. The result of a
sentence typed on the keyboard is displayed, except that to avoid excessive typeout
nothing is displayed if the last fragment executed in the sentence is an assignment. If you
are at the keyboard while you are reading this book, you can type the examples and see
the responses, or experiment on your own.
Here is a simple program to add twice the left argument to three times the right
argument:
add2x3y =: dyad : '(2 * x.) + 3 * y.'
We can run this program by giving it operands:
1 2 3 add2x3y 4 5 6
14 19 24
Instead of simply displaying the result, we can assign it to a noun:
a =: 1 2 3 add2x3y 4 5 6
We can inspect the value assigned to the noun by typing the name of the noun:
a
14 19 24
We can use the noun in an expression:
2 * a
28 38 48
We can create a new verb that operates on the noun:
twicea =: monad : '2 * a'
twicea ''
28 38 48
Notice the '' after the invocation of twicea. Remember, to invoke a verb you must
give it an operand, even if the verb doesn't use an operand. '' is just an empty string; 0
or any other value would work too. If you leave out the operand, J will show you the
value of the name; since twicea is a verb, its value is the definition of the verb:
twicea
3 : '2*a'
Of course, in any practical application you will need to have most of your programs
in a library so you can quickly make them all available to J. J calls these libraries scripts
(filename extension '.ijs') and runs them with the load verb, for example:

13
load 'system\packages\misc\jforc.ijs'
load reads lines from the script and executes them. These lines will normally be all
the verb and noun definitions your application needs, possibly including load
commands for other scripts. A script may end with a line executing one of the verbs it
defined, thereby launching the application; or, it may end after defining names, leaving
you in control at the keyboard to type sentences for J to execute.
Note: Names defined by private assignment (using =.) when
a script is loaded are not available outside the script. If you
want to define names for use elsewhere, make sure you use
=: for your assignments within a script.
If you are used to debugging with Visual C++™ or the like, you will find the
environment less glitzy and more friendly. If you want to change a verb (function), you
simply edit the script, using the editor of your choice (I use the built-in editor provided
with J), and rerun it. The verb will be updated, but all defined nouns (objects) will be
unchanged. Even if you are running a large application—yea, even if the application is in
the middle of reading from an asynchronous socket—you can change the program,
without recompiling, relinking, or reinitializing. If you'd like to add some debugging
code while the system is running, go right ahead. This easy interaction with an executing
program is one of the great benefits of programming in J.
Interrupting Execution
If a J verb is taking too long to run, signal it to stop by running the Jbreak program
that is supplied as part of the J installation. Control will return to the keyboard.
Errors
When a sentence contains an error, J stops and displays the sentence along with a
terse error message. Refer to the chapter on Error Messages for explanation of the error.

The Execution Window; Script Windows


When J starts it displays its execution window. The title of the execution window
ends with the characters '.ijx'. The only way to have a sentence executed is to have
the sentence sent to the execution window. The simplest way to do that is by typing the
sentence into the execution window, as we have been doing in the examples so far.
The execution window is an edit window and a session log as well as a place to type
sentences for execution. If you put the cursor on some line other than the last and press
ENTER, the line you were on will be copied to the bottom of the session log as if you had
typed it for execution. You can then edit the line before pressing ENTER again to
execute it.
For convenience in editing, you may create other windows which will be script
windows. Usually these windows will contain J scripts that you are working on, and the
editor that manages the script windows is familiar with the syntax of J. You create a
script window by clicking File on the Menu Bar and then selecting New ijs, Open, or
Recent.

14
Sentences that you type into a script window are not automatically executed by J; you
must copy them into the execution window to have them executed. You can use the
script-window editor to send lines from a script to the execution window: click Run on
the Menu Bar and then File, Selection, or Window as appropriate.
To run a selection of lines from a script window, be sure to
use Run|Selection rather than cut-and-paste. If you paste a
number of lines into the execution window, only the last one
will be executed.
It is important to remember that the script windows exist only for your convenience in
editing and are not used during execution. If you make a change to a script window, you
need to Run that window to cause the lines in the script to be executed.
If you are debugging a script and you remove a definition from the script and Run it,
the definition will not be removed from the J session. Running the script is like entering
the sentences one by one from the keyboard, and not-defining the name does nothing to
expunge an established definition. To remove the old definition, use
4!:55 <'expiredname' or start a fresh session of J.

Names Defined at Startup


When J starts, a number of useful names are defined. Rather than discuss them all, I
will show you how they come to be defined so you can study them when you need to.
When J starts, it executes the script
J-directory\system\extras\config\profile.ijs which then executes
the script J-directory\system\extras\util\boot.ijs . boot.ijs in
turn executes a series of scripts in J-directory\system\main which define the
starting environment. Look at these scripts to see what they define.
If you want to add your own initial definitions, do so either by adding commands at
the end of profile.ijs or by creating your own startup script in
J-directory\system\extras\config\startup.ijs .

Step-By-Step Learning: Labs


The Labs are interactive demos describing various topics in J. To run the lab for
printf, start a J session, on the menu bar select Studio|Labs…, then select the lab you are
interested in, then press 'Run'. The lab provides explanatory text interspersed with
examples executed in your J session which you are free to experiment with as you step
through the lab.
I recommend that every now and again you tarry a while among the labs, running
whichever ones seem interesting. Much of the description of the J system can be found
only there.

15
J Documentation
The J documentation is available online. Pressing F1 brings up the Vocabulary page,
from which you can quickly go to the Dictionary's description of each J primitive. At the
top of each page of documentation are links to the manuals distributed with J: these are:
The Index to all documentation;
The User Manual which describes components of J that are not in the language itself,
including system libraries and external interfaces;
The J Primer, an introduction to J;
J Phrases, a collection of useful fragments of J (you will need to finish this book
before trying to use J Phrases);
The J Dictionary, the official definition of the language;
Release Notes for all releases of J;
A description of foreign conjunctions (!:);
A description of the operands to the wd verb (Windows interface).

Getting Help
Your first step in learning J should be to sign up for the J Forum at
www.jsoftware.com. A great many experienced J users monitor messages sent to the
Forum and are willing to answer your questions on J, from the trivial to the profound.

16
4. A First Look At J Programs
Before we get into learning the details of J, let's look at a couple of realistic, if simple,
problems, comparing solutions in C to solutions in J. The J code will be utterly
incomprehensible to you, but we will nevertheless be able to see some of the differences
between J programs and C programs. If you stick with me through this book, you will be
able to come back at the end and understand the J code presented here.

Average Daily Balance


Here is a program a bank might use. It calculates some information on accounts
given the transactions that were performed during a month. We are given two files, each
one containing numbers in lines ended by (CR,LF) and numeric fields separated by TAB
characters (they could come from spreadsheets). Each line in the Accounts file contains
an account number followed by the balance in the account at the beginning of the month.
Each line in the Journal file contains an account number, the day of the month for a
transaction, and the amount of the transaction (positive if money goes into the account,
negative if money goes out). The records in the Journal file are in order of date, but not
in order of account. We are to match each journal entry with its account, and print a line
for each account giving the starting balance, ending balance, and average daily balance
(which is the average of each day's closing balance). The number of days in the month is
an input to the program, as are the filenames of the two files.
I will offer C code and J code to solve this problem. To keep things simple, I am not
going to deal with file-I/O errors, or data with invalid format, or account numbers in the
Journal that don't match anything in the Accounts file.
C code to perform this function might look like this:
#include <stdio.h>
#define MAXACCT 500
// Program to process journal and account files, printing
// start/end/avg balance. Parameters are # days in current
// month, filename of Accounts file, filename of Journal file
void acctprocess(int daysinmo, char * acctfn, char *jourfn)
{
FILE fid;
int nacct, acctx;
float acctno, openbal, xactnday, xactnamt
struct {
float ano; // account number
float openbal; // opening balance
float prevday; // day number of last activity
float currbal; // balance after last activity
float weightbal; // weighted balance: sum of closing balances
} acct[MAXACCT];
// Read initial balances; set day to start-of-month, sum of balances to 0

17
fid = fopen(acctfn);
for(nacct = 0;2 == fscanf(fid,"%f%f",acctno,openbal) {
acct[nacct].ano = acctno;
acct[nacct].openbal = openbal;
acct[nacct].prevday = 1;
acct[nacct].currbal = openbal;
acct[nacct].weightbal = 0;
++nacct;
}
fclose(acctfn);
// Process the journal: for each record, look up the account
// structure; add closing-balance values for any days that
// ended before this journal record; update the balance
fid = fopen(jourfn);
while(3 == fscanf(fid,"%f%f%f",acctno,xactnday,xactnamt) {
for(acctx = 0;acct[acctx].ano != acctno;++acctx);
acct[nacct].weightbal +=
acct[nacct].currbal * (xactnday - acct[nacct].prevday);
acct[nacct].currbal += xactnamt;
acct[nacct].prevday = xactnday;
}

// Go through the accounts. Close the month by adding


// closing-balance values applicable to the final balance;
// produce output record
for(acctx = 0;acctx < nacct;++acctx) {
acct[nacct].weightbal +=
acct[nacct].currbal * (daysinmo - acct[nacct].prevday);
printf("Account %d: Opening %d, closing %d, avg %d\n",
acct[acctx].ano, acct[acctx].openbal, acct[acctx].currbal,
acct[acctx].weightbal/daysinmo);
}
fclose(fid);
}
The corresponding J program would look like this:

18
NB. Verb to convert TAB-delimited file into numeric array
rdtabfile =: (0&".;.2@:(TAB&,)@:}:);._2) @ ReadFile @<
NB. Verb to process journal and account files
NB. y. is (# days in current month);(Account filename);
NB. (Journal filename)
acctprocess =: monad define
'ndays acctfn jourfn' =: y.
NB. Read files
'acctano openbal' =. |: rdtabfile acctfn
'jourano jourday jouramt' =. |: rdtabfile jourfn
NB. Verb: given list of days y., return # days that
NB. each balance is a day's closing balance
wt =. monad : '(-~ 1&(|.!.(>:ndays))) 0{"1 y.'
NB. Verb: given an Account entry followed by the Journal
NB. entries for the account, produce (closing balance),
NB. (average daily balance)
ab =. monad : '(wt y.)({:@] , (%&ndays)@(+/)@:*)+/\1{"1 y.'
NB. Create (closing balance),(average daily balance) for
NB. each account. Assign the start-of-month day (1) to the
NB. opening balance
cavg =. (acctano,jourano) ab/.(1,.openbal),jourday,.jouramt
NB. Format and print all results
s =. 'Account %d: Opening %d, closing %d, avg %d\n'
s&printf"1 acctano ,. openbal ,. cavg
''
)
Let's compare the two versions. The first thing we notice is that the J code is mostly
commentary (beginning with NB.). The actual processing is done in 3 lines that read the
files, 3 lines to perform the computation of closing and average balance, and 2 lines to
print the results. J expresses the algorithm much more briefly.
The next thing we notice is that there seems to be nothing in the J code that is looping
over the journal records and the accounts. The commentary says 'create balances for each
account' and 'produce average daily balance for an account', tasks that clearly require
loops, and yet there is nothing resembling loop indexes. This is one of the miracles of J:
loops are implied; in C terminology, they are expressions rather than statements,
and so they can be assembled easily into single lines of code that replace many nested
loops. We will be spending a lot of time learning how to do this.
We also note that there is nothing in the J code corresponding to the
#define MAXACCT 500 in the C. This is one of the things that makes programming in
J so pleasant: you don't have to worry about allocating storage, or freeing it, or wondering
how long is long enough for a character-string variable, or how big to make an array.
Here, even though we don't know how many accounts there are until we have read the
entire Accounts file, we simply read the file, split it into lines and numbers, and let the
interpreter allocate as much storage as it needs to hold the resulting array.

19
The last thing to see, and perhaps the most important, is that the C version is just a toy
program. It searches through the Accounts information for every record in the Journal
file. We can test it with a small dataset and verify that it works, but if we scale it up to
10,000 accounts and 1,000,000 journal entries, we are going to be disappointed in the
performance, because its execution time will be proportional to A*J where A is the
number of accounts and J the number of journal entries. It is every programmer's dread:
a function that will have to be rewritten when the going gets tough.
The J version, in contrast, will have execution time proportional to (A+J)*log(A+J).
We did nothing meritorious to achieve this better behavior; we simply expressed our
desired result and let the interpreter pick an implementation. Because we 'think big'—we
treat the entire Journal and Accounts files as units—we give the interpreter great latitude
in picking a good algorithm. In many cases the interpreter makes better decisions than
we could hope to, because it looks at the characteristics of the data before it decides on its
algorithm. For example, when we sort an array, the interpreter will use a very fast
method if the range of numbers to be sorted is fairly small, where 'fairly small' depends
on the number of items to be sorted. The interpreter takes great care in its
implementation of its primitives, greater care than we can normally afford in our own C
coding. In our example, it will use a high-speed method for matching journal entries with
accounts.

Calculating Chebyshev Coefficients


This algorithm for calculating coefficients of the Chebyshev approximation of a
function is taken verbatim from Numerical Recipes in C. I have translated it into J just so
you can see how compact the J representation of an algorithm can be. Again, the J code
will be gobbledygook for now, but it's concentrated gobbledygook.

20
// Program to calculate Chebyshev coefficients
// Code taken from Numerical Recipes in C 1/e
#include <math.h>
#define PI 3.141592653589793
void chebft(a,b,c,n,func)
float a,b,c[ ];
float (*func)();
int n;
{
int k,j;
float fac,bpa,bma,f[300];

bma = 0.5 * (b-a)


bpa = 0.5 * (b+a)
for(k = 0;k<n;k++) {
float y = cos(PI*(k+0.5)/n);
f[k] = (*func)(y*bma+bpa);
}
fac = 2.0/n;
for (j = 0;j<n;j++) {
double sum = 0.0;
for(k = 0;k<n;k++)
sum += f[k] * cos(PI*j*(k+0.5)/n);
c[j] = fac*sum;
}
}
J version:
chebft =: adverb define
:
f =. u. 0.5 * (+/y.) - (-/y.) * 2 o. o. (0.5 + i. x.) % x.
(2 % x.) * +/ f * 2 o. o. (0.5 + i. x.) *"0 1 (i. x.) % x.
)

21
5. Declarations
J has no declarations. Good riddance! No more will you have to warn the computer
of all the names you intend to use, and their types and sizes. No more will your program
crash if you step outside an array bound. You specify the calculations you want to
perform; if, along the way, you want to assign a result to a name, J will allocate enough
space for the data. It will free the space when the name is no longer needed.
Seasoned C programmers have learned to use declarations to create a web of type-
checking, making sure that objects pointed to are of the expected type. This is an
example of making a virtue of necessity. Since J solves the problem much more
directly—by not having pointers at all—you will soon lose your uneasiness with weak
typing.

Arrays
But, you ask, without declarations, how does the computer know that a name
represents an array? For that matter, how do I know that a name represents an array?
The answer affords a first glimpse of the power of J. Every J verb, whether a
primitive (operator) or a user-written verb (function), accepts arguments that can be
arrays, even multidimensional arrays. How is this possible? Like this: Suppose you
write a verb that works with 2-dimensional arrays. Part of your verb definition will
indicate that fact. If your verb is executed with an argument that is a 3-dimensional
array, J will automatically split the 3-dimensional array into a sequence of 2-dimensional
arrays, call your verb, and put the pieces back together into an array of results.
We will very soon go into this procedure in great detail. For now, you should learn
the vocabulary J uses to deal with arrays.
What C calls an n-dimensional array of rank i×j×…×k is in J an array of rank n
with axes of length i,j,…,k.
Every noun (variable or object) has a shape which is the array (of rank 1) made by
concatenating the lengths of all its axes. For example, if q is the array corresponding to
the C array defined by the declaration
int q[4][5][6];
its shape is the array 4 5 6 . As you can see, the number of items in the shape is
exactly the rank.
Note: a sequence of numbers written with no intervening
punctuation defines a numeric array of rank 1 (i. e. a list).
You may have to use parentheses if you have adjacent
numbers that you don't want to have made into a list.
Unlike in C, an array in J may have one or more axes of length 0. Such an array has
no atoms, but its rank is still the number of its axes.

22
A single number or character is called an atom (object of basic type) which is said
to have the type numeric or character as appropriate. (Actually, there are types other than
number and character, including a type that resembles a structure, but we won't get to
them for a while). An atom is also called a scalar. An atom is defined to have rank 0;
therefore, its shape is an array with 0 items, i. e. an empty array of rank 1.
Just as in C, every atom of an array must have the same type.

Cells
Because the execution of every J verb involves breaking the argument into pieces,
presenting the pieces to the verb, and assembling results, J has a vocabulary for
describing these operations.
A rank-3 array of shape 4 5, 6 such as the one defined in C by the declaration
int q[4][5][6];
can be thought of as an array of 4 elements, each with rank 2 and shape 5 6, or as a 4×5
array of elements, each with rank 1 and shape 6, or as a 4×5×6 array of rank-0 atoms.
The term cell is used to indicate the rank of the elements that will be operated on. A
0-cell is an atom, a 1-cell is an element of rank 1, a 2-cell is an element of rank 2, and so
on.

Once you have picked a cell size, you can think of your noun as an array of cells; the
shape of that array is called the frame of the noun relative to the chosen rank of cell. It
follows that the frame, concatenated with the shape of the cells, will be equal to the shape
of the noun. The frame itself (like all shapes) is an array of rank 1.
The diagram illustrates cells of different ranks. Note that the twenty 6-atom 1-cells
are arranged in a 4×5 array; this is the meaning of the frame of the 1-cells. The four 5×6
2-cells are arranged as a vector of 2-cells; this is the meaning of their frame.
A selected cell is analogous to the subarray selected by indexing in C. Using q as
defined above, in C q[3] is a 5×6 array (i. e. a 2-cell); q[1][0] is a 6-element vector (i. e.
a 1-cell); q[2][0][3] is a scalar (0-cell).
The noun q we have been using as an example can be thought of in any of the
following 4 ways:

23
Frame Cells
as an array of Length Value Rank Shape
0-cells 3 4 5 6 0 (empty)
1-cells 2 4 5 1 6
2-cells 1 4 2 5 6
3-cells 0 (empty) 3 4 5 6

Choosing Axis Order


Because J verbs operate on cells of nouns, you should choose an order of axes that
makes the cells meaningful for your application. Referring to the figure, we can see that
the groups of items that fall into horizontal strips (1-cells) or horizontal slabs (2-cells)
will be easy to operate on individually. Vertical strips or slabs will not correspond to
cells and so will not be accessible individually; to work on them we may have to reorder
the axes of the noun to make them correspond to cells. Such reordering of axes is easy in
J but it can often be avoided by ordering the axes properly in the first place.
Negative Cell-Rank; Items
In some cases, you may know the length of the frame and want to define the cells to
have whatever rank is left over (for example, you may have a noun with one cell per
employee, but you may not know the rank of the cells). We say that you are selecting the
cells of the noun relative to the given frame. Negative cell-ranks indicate this. A _1-cell
has the shape corresponding to a frame of length 1 (5 6 in our example), a _2-cell has
the shape corresponding to a frame of length 2 (6 in our example), and so on. If the
specified frame is longer than the rank of the noun, the entire shape of the noun is used
for the frame (and the cells are 0-cells, i. e. atoms). In our example, a _3-cell, a _4-cell, a
_5-cell, etc., all refer to atoms. As an important case of this, the _1-cell of an atom is the
atom itself.
_1-cells are so important in J that they are given the name items. Our example has 4
items, each of shape 5 6 . An atom has one item, itself.
Remember: an atom has one item: itself.
The index of an item in an array is the sequence number of the item from the
beginning of the array. The first item in an array has the index 0, just as in C.
Lists
When we choose to view an array as a collection of its items, we say that the array is
a list of its items. In our example above, the items of the 4×5×6 array are 5×6 arrays, and
we say that the whole array is a list of 4 items each with shape 5 6 (equivalently, we say
that it is a list of four 5×6 arrays). So many of J's primitives operate on items of their
operands that we will find ourselves usually thinking of an array as a list of its items.

24
When the word 'list' is used without any indication of what the list contains, the list is
assumed to contain atoms. So, 'the list x' refers to an array of rank 1 (one-dimensional
array). 0 3 5 is a numeric list.
Note that J's use of the term 'list' has nothing to do with linked lists such as you are
familiar with, where an element in the list contains a pointer to other elements. Since J
has no pointers at all, you will not need that meaning, and you can get used to calling
rank-1 arrays 'lists'. A list can also be called a vector.

Phrases To Memorize
An array is a list of its items.
An atom has one item, itself.
The rank of a noun is the length of its shape.
The shape of an atom is the empty list.
The suffixes of the shape of a noun give the shapes of its cells: the k trailing atoms of
the shape of a noun give the shape of its k-cell.
The frame of a noun with respect to k-cells is the shape of the noun, with the last k
atoms of the shape removed.

Constant Lists
A character or numeric list can be created simply by including the list in a sentence.
We have seen that a sequence of numbers separated by spaces is recognized as a single
word representing the list. Similarly, a character or a character list can be represented
directly by a quoted string. C distinguishes between single-character constants (such as
'a') and strings (such as "abc"), using single quotes for characters and double quotes for
strings. J uses only single quotes for defining character constants (the " character is a
primitive in its own right). If exactly one character is between the quotes, the value is an
atom; if none or more than one, the result is a list.

Array-creating Verbs
Now that we know how to talk about arrays, we might as well create a few and see
what they look like. As mentioned earlier, every J verb can be used to create an array—
there are no special 'declaration' verbs—but we will start with a couple that do little else.
The J lines are taken from an interpreter session; you can type them into your own
session and get the same results. The indented lines were typed into J, and the
unindented ones are J's responses.
Dyad $ ($hape) and monad $ ($hape Of)
The verb dyad $ is invoked as x $ y . The result of dyad $ has the frame x
relative to the rank of the items of y, and is made up of the items of y, repeated cyclically
as needed. It follows that the shape of this result is x concatenated with the shape of an
item of y .

25
We will have to work together on this. Confronted with a definition like that, you
might: (a) decide that J must be a language for tax accountants, and give up; (b) decide
the definition is Greek and go on, hoping it will make sense later; (c) try a few examples
to get an idea for what the definition means; (d) read it over and over again until you
understand it. I hope you will eschew (a) and (b), and settle for no less than full
understanding. For my part, I will offer a few useful examples that you can compare
against the definition. Not everything in J will be as abstract as this.
5 $ 2
2 2 2 2 2
The simplest case, creating (and displaying) a list of 5 items, each of which is 2 . Let's
see how this result matches the definition. y is a scalar, so it has one item, which is also
a scalar. Therefore, the result has the shape 5 (x (i. e. 5) concatenated with the shape of
an item of y; the shape of a scalar item of y is the empty list; 5 concatenated with an
empty list is a list with the single element 5). The scalar is repeated to fill the 5 items of
the result. J displays a 1-cell on a single line, as shown.
5 $ 'ab'
ababa
Now y is a list, but its items are still scalars, with rank 0 and shape empty; so the result
still has the shape 5 . The 5 items come from the items of y, cyclically.
We can distill the foregoing analysis above to the observation that when y is an atom
or a list, x specifies the shape of x $ y .
4 4 $ 'There is a tide in the affairs of men'
Ther
e is
a t
ide
The items of y are still scalars, with rank 0 and shape empty; the result has the shape
4 4 . The 16 items come from the items of y, cyclically. Not all items of y are used. J
displays a rank-2 array as a sequence of lines, one for each 1-cell.
0 $ 2
(The display is a single blank line) Just like 5 $ 2, but the resulting list has 0 items,
i. e. it is an empty list.
1 $ 2
2
Similarly, a 1-item list.
(0 $ 2) $ 2
2
Here (0 $ 2) produces an empty list, as we saw above, and that is the x to the second
$ . The items of y are still scalars, so the result has shape empty (an empty list
concatenated with an empty list), i. e. it is a scalar.
The displays of a scalar and a 1-item list are identical. Does that mean that a scalar is
the same thing as a 1-item list? No. I mean no. NO! They are not (I say this with the

26
same resignation as when I tell my kids not to rollerblade too fast down our street,
knowing that only painful experience will drive the message home). How can you tell
them apart? What we need is a way to see the shape of a noun.
That way is monad $ . The result of $ y is the shape of y (always a numeric list).
For example:
$ 1 2 3 4
4
A 4-item list has the shape 4 . Did you forget that 1 2 3 4 is a single list rather than 4
separate numbers? You can ask the interpreter how it splits a line into words by using
monad ;: :
;: '$ 1 2 3 4'
+-+-------+
|$|1 2 3 4|
+-+-------+
The words are shown in boxes. The list 1 2 3 4 is recognized as a single word.
$ 6
The shape of a scalar is a 0-length list, as we have seen.
$ 1 $ 2
1
Remember, all sentences are executed right-to-left, so this is $ (1 $ 2), which gives
the shape of the 1-item list. When a verb can be invoked dyadically, it is, so the
rightmost $ is executed as a dyad, not as a monad.
$ (0 $ 2) $ 2
Here, we get the shape of the scalar—an empty list.
$ 'a'
A single character is an atom, whose shape is the empty list.
$'abc'
3
A 3-item list, one item for each character.
$ ''
0
'' is the empty character string, which you will see a lot of. Because it is easy to type, it
is the value most often used when an empty list of any type will do.
Executing monad $ twice gives the rank: $ $ y is the rank of y (as a single-item
list). I suggest you not read on until you understand why.
Resuming our inquiries into dyad $, we have
2 5 $ 1 10
1 10 1 10 1
10 1 10 1 10
Again y is a list, so the items of y are scalars. The shape of the result is 2 5, and the
items of y are repeated to fill that shape. Note that the corresponding atoms in each cell
are aligned in the display.

27
1 5 $ 1 10
1 10 1 10 1
Similarly, but now the result has shape 1 5. This is not the same as a 5-item list, which
has shape 5 . Again, monad $ shows the shape:
$ 1 5 $ 1 10
1 5
When y is not a scalar or a list, its items are not scalars, and x does not give the shape
of the result. Let us work through an example using the definition of x $ y :
3 $ 1 5 $ 1 10
1 10 1 10 1
1 10 1 10 1
1 10 1 10 1
Remember, this is processed as 3 $ (1 5 $ 1 10). The parenthesized part
produces an array of shape 1 5; since this has rank 2, its items are its 1-cells, each with
shape 5. The shape of the overall result is x concatenated with the shape of an item of y,
to wit 3 5. This is populated with the cells of y, of which there is only 1.
3 $ 2 5 $ 'There is a tide in the affairs of men'
There
is a
There
You should be able to explain where each line came from, and you should note that in
general, x specifies the frame of x $ y with respect to items of y . When y is a list
or an atom, its items are atoms and x gives the entire shape of the result.
2 2 $ 2 5 $ 1 10
1 10 1 10 1
10 1 10 1 10
1 10 1 10 1
10 1 10 1 10
$ 2 2 $ 2 5 $ 1 10
2 2 5
Now the shape of the result is 2 2 5, a rank-3 array. J displays the 2-cells with a blank
line in between. Similarly, a rank-4 array is displayed as all the 3-cells with 2 blank lines
in between, and so on for higher ranks.
We have seen that the display of a zero-length list is a single blank line: proper, as
there is one list, and it has no items. The display of a rank-2 array with no items is
different: here we have zero lists, so we should expect no lines at all. This is indeed what
happens:
0 0$0
(there is no blank line). This is the result you should produce if you want a function to
display nothing.
Here are two exercises. Once you can explain each result, you will be well on your
way to becoming a J programmer. What will each of these sentences produce (answer on
the next page)?

28
3 1 $ 2 5 $ 1 10
2 3 $ 2 5 $ 1 10 15

29
Solutions:
3 1 $ 2 5 $ 1 10
1 10 1 10 1
10 1 10 1 10
1 10 1 10 1
2 3 $ 2 5 $ 1 10 15
1 10 15 1 10
15 1 10 15 1
1 10 15 1 10
15 1 10 15 1
1 10 15 1 10
15 1 10 15 1
Monad # (Tally)
The result of # y is a scalar, the number of items in y . This is the first item in the
list $y, except that if y is an atom, $y is empty but #y is 1 (because, remember, an atom
has one item, itself). If y is a list, #y is the length of the list. Quiz question: What is the
difference between the results of $ 1 2 3 and # 1 2 3?
$ 1 2 3
3
# 1 2 3
3
Answer: the result of monad $ is always a list, but the result of monad # is a scalar:
$ $ 1 2 3
1
$ # 1 2 3
#$y, like $$y, gives the rank of y . Since monad # produces a scalar rather than a
list, #$y is usually preferred. Just remember that the length of the shape is the rank.
Monad i. (Integers)
Monad i. accepts a scalar or vector operand and creates an array. i. y produces
the same result as y $ ints, where ints is the list of all nonnegative integers in
order. Examples:
i. 5
0 1 2 3 4
A list of 5 items; the items are ascending integers.
i. 2 3
0 1 2
3 4 5
A rank-2 result.

30
i. 2 3 4
0 1 2 3
4 5 6 7
8 9 10 11

12 13 14 15
16 17 18 19
20 21 22 23
A rank-3 result.
i. 0

A list of 0 items.
i. _5
4 3 2 1 0
If the argument is negative, the absolute value is used for the shape, but the items run in
reverse order.

31
6. Loopless Code I—Verbs Have Rank
Most J programs contain no loops equivalent to while and for in C. J does contain
while. and for. constructs, but they carry a performance penalty and are a wise
choice only when the body of the loop is a time-consuming operation. You are just going
to have to learn to learn to code without loops.
I think this is the most intimidating thing about learning J—more intimidating even
than programs that look like a three-year-old with a particular fondness for periods and
colons was set before the keyboard. You have developed a solid understanding of loops,
and can hardly think of programming without using them. But J is a revolutionary
language, and all that is solid melts into air: you will find that most of your loops
disappear altogether, and the rest are replaced by small gestures to the interpreter
indicating your intentions.
Come, let us see how it can be done. I promise, if you code in J for 6 months, you
will no longer think in loops, and if you stay with it for 2 years, you will see that looping
code was an artifact of early programming languages, ready to be displayed in museums
along with vacuum tubes, delay lines, and punched cards. Remember, in the 1960s
programmers laughed at the idea of programming without gotos!
You are not used to classifying loops according to their function, but I am going to do
so as a way of introducting J's primitives. We will treat the subject of loopless iteration in
6 scattered chapters, showing how to replace different variants of loops:
1. Loops where each iteration of the loop performs the same operation on different
data;
2. Loops that apply an operation between all the items of the array, for example
finding the largest item;
3. Loops where the operation to be performed on each cell is different;
4. Loops that are applied to regularly-defined subsets of the data;
5. Loops that are applied to subsets of the data defined irregularly;
6. Loops that accumulate information between iterations of the loop;
7. Loops that implement finite-state machines.
The simplest case is the most important, and we start with a few experiments.

Examples of Implicit Loops


2 + 3 4 5
5 6 7
The verb dyad + is addition, and we have our first example of an implicit loop: the left
argument 2 was added to each atom in the right argument.

32
1 2 3 + 4 5 6
5 7 9
And look! If each operand is a list, the respective items are added. We wonder if the
behavior of 2 + 3 4 5 was because items of the shorter operand are repeated
cyclically:
1 2 + 4 5 6
|length error
| 1 2 +4 5 6
Evidently not. A 'length error' means that the operands to + did not 'agree' (and you get
an error if you try to add them). We will shortly understand exactly what this means.
i. 2 3
0 1 2
3 4 5
A reminder of what monad i. does.
0 100 + i. 2 3
0 1 2
103 104 105
Whoa! The atoms of the left operand were applied to rows of the right operand.
Interesting. This seems to be some kind of nested implicit loop.
Let's learn a couple of more verbs, monad #. and monad #: . Monad #: creates the
binary representation of an integer (i. e. a list of 0s and 1s), and monad #. is its inverse,
creating the integer from the binary representation. For the longest time I couldn't
remember which was which, but at last I saw the mnemonic: the verb with the single dot
(#.) creates an atom from a list; the verb with multiple dots (#:) creates a list from an
atom:
#: 5
1 0 1
#. 1 0 1
5
Yes, they seem to perform as advertised. They can be applied to arrays:
]a =. #: 5 9
0 1 0 1
1 0 0 1
Look: the result is not a rank-1 list, but rather a rank-2 array, where each item has the
binary representation of one operand value (and notice, an extra leading zero was added
to the representation of 5). The little trick with ]a =. will be explained later, but for
now just think of ]a =. as 'assign to a and display the result'. With a assigned, we
have:
#. a
5 9
This seems to be the desired result, but on reflection we are puzzled: how did the
interpreter know to apply #. to each 1-cell rather than to each 0-cell? Contrast this result
with the result of the verb monad +:, which means 'multiply by 2':

33
+: a
0 2 0 2
2 0 0 2
Evidently the verbs themselves have some attribute that affects the rank of cell they are
applied to. It's time for us to stop experimenting and learn what that attribute is.

The Concept of Verb Rank


Every verb has a rank—the rank of the cells to which it is applied. If the rank of the
verb's operand is smaller than the rank of the verb, the verb is applied to the entire
operand and it is up to the author of the verb to ensure that it produces a meaningful
result in that case.
Dyads have a rank for each operand, not necessarily the same.
A verb's rank can be infinite (_), in which case the verb is always applied to the
operand in its entirety. In other words, if a verb has infinite rank for an operand, that
operand is always processed as a single cell (having the rank of the operand).
If you don't know the rank of a verb, you don't know the verb. Using a verb of
unknown rank is like wiring in a power-supply of unknown voltage—it will do
something when you plug it in; it might even work; but if the voltage is wrong it will
destroy what it's connected to. Avoid embarrassment! Know the rank of the verbs you
use.
The definition page of each J verb gives the ranks of the verbs defined on the page,
right at the top of the page after the name of the verb. Since most pages define both a
monad and a dyad, you will usually find 3 numbers: the first is the rank of the monad, the
other two are the left and right rank of the dyad. For example, click up the page for #:
and you will see
#: _ 1 0
which means that monad #: has infinite rank, while dyad #: has left rank 1 and right
rank 0. For any verb, including user-written verbs, you can ask the interpreter the rank
by typing verbname b. 0 :
#: b. 0
_ 1 0

Verb Execution—How Rank Is Used (Monads)


The implicit looping in J results from the interplay of verb rank and noun rank. For
monads, it goes like this:
1. Figure out the rank r of the cells that will be operated on; this will be the smaller
of rank of the verb and the rank of the operand. This rule applies even if the verb
has infinite rank: r will be the rank of the operand, which is another way of saying
that the verb applies to the operand in its entirety.
2. Find the frame f of the operand with respect to cells of rank r.
3. Think of the operand as an array with shape f whose items are cells of rank r.
Apply the verb to each r-cell, replacing each cell with the result of the verb.

34
Obviously, this will yield an array of shape f whose items have the shape of the
result of applying the verb to an r-cell.
Let's look at some simple examples:
i. 2 2
0 1
2 3
This will be the right operand.
+: i. 2 2
0 2
4 6
The steps to get this result are:
The verb rank is 0 and the noun rank is 2, so we will be
applying the verb to 0-cells. The frame f is 2 2

Think of the operand as a 2×2 array of 0 1


0-cells: 2 3

0 2
The verb is applied to each cell:
4 6

Since each result is an atom, i. e. a 0-cell, the 0 2


result is a 2×2 array of 0-cells, i. e. an array of 4 6
shape 2 2
Figure 1. Execution of +: i. 2 2

Another example:
]a =. 2 2 4 $ 0 0 1 1 0 0 0 1 0 1 0 0 0 0 1 0
0 0 1 1
0 0 0 1

0 1 0 0
0 0 1 0
This is a rank-3 array.

35
#. a
3 1
4 2

The verb rank is 1 and the noun rank is 3, so we will be applying the
verb to 1-cells. The frame f is 2 2

Think of the operand as a 2×2 array of 0011 0001


1-cells: 0100 0010

3 1
The verb is applied to each cell:
4 2

Since each result is an atom, i. e. a 0-cell, the 3 1


result is a 2×2 array of 0-cells, i. e. an array of 4 2
shape 2 2
Figure 2. Execution of #. 2 2 4 $ 0 0 1 1 0 0 0 1 0 1 0 0 0 0 1 0

Controlling Verb Execution By Specifying a Rank


The implicit loops we have used so far are interesting, but they are not powerful
enough for our mission of replacing all explicit loops. To understand the deficiency and
its remedy, consider the new verb monad +/, which creates the total of the items of its
operand (just think of it as 'monad SumItems'):
+/ 1 2 3
6
The result was 1 + 2 + 3, as expected.
i. 2 3
0 1 2
3 4 5
+/ i. 2 3
3 5 7
The result was 0 1 2 + 3 4 5, as expected (remember that the items are added, and
the items of i. 2 3 are 1-cells). Adding together a pair of 1-cells adds the respective
atoms, as we will soon learn.
This application of monad +/ to a rank-2 array corresponds to the C code fragment:
for(j = 0;j<3;++j)sum[j] = 0;
for(i = 0;i<2;++i)
for(j = 0;j<3;++j)sum[j] += array[i][j];
Suppose we wanted to add up the items of each row, as in the C code fragment

36
for(i = 0;i<2;++i) {
sum[i] = 0;
for(j = 0;j<3;++j)sum[i] += array[i][j];
}
to produce the result 3 12? How can we do it in J? What we have learned so far is not
enough, but if we had a way to make monad +/ apply to 1-cells—if we could make
monad +/ have rank 1—our problem would be solved: the implicit looping would cause
each row to be summed and the results collected.
You will not be surprised to learn that J does indeed provide a way to apply monad
+/ on 1-cells. That way is the rank conjunction " .
We will learn all about conjunctions later on—the syntax is a little different than for
verbs—but for now, we'll try to understand this " . It's used like this:
u"n
to produce a new verb that is u applied to n-cells individually. This is a simple idea,
but its ramifications spread wide. As a first example:
+/"1 i. 2 3
3 12
This is what we were looking for. It happened this way:

The verb rank is 1 and the noun rank is 2, so we will be applying


the verb to 1-cells. The frame f is 2

Think of the operand as a list of 2 1-cells: 012 345

The verb monad +/ is applied to each cell: 3 12

Since each result is an atom, i. e. a 0-cell, the


result is a list of 2 0-cells, i. e. an array of shape 3 12
2
Figure 3. Execution of +/"1 i. 2 3

Examples Of Verb Rank


Here are some more examples using a rank-3 array as data:

37
i. 2 3 4
0 1 2 3
4 5 6 7
8 9 10 11

12 13 14 15
16 17 18 19
20 21 22 23

+/"1 i. 2 3 4
6 22 38
54 70 86

The verb rank is 1 and the noun rank is 3, so we will be applying the
verb to 1-cells. The frame f is 2 3

Think of the operand 0123 4567 8 9 10 11


as a 2×3 array of 1-cells: 12 13 14 15 16 17 18 19 20 21 22 23

The verb monad +/ is 6 22 38


applied to each cell: 54 70 86

Since each result is an


atom, i. e. a 0-cell, the 6 22 38
result is a 2×3 array of 54 70 86
0-cells, i. e. an array of
shape 2 3
Figure 4. Execution of +/"1 i. 2 3 4

38
+/"2 i. 2 3 4
12 15 18 21
48 51 54 57

The verb rank is 2 and the noun rank is 3, so we will be applying the
verb to 2-cells. The frame f is 2

0123 12 13 14 15
Think of the operand
4567 16 17 18 19
as a list of 2 2-cells:
8 9 10 11 20 21 22 23

The verb monad +/ is


applied to each cell. As
we have learned, this sums 12 15 18 21 48 51 54 57
the items, making each
result a rank-1 list

Since each result is a


rank-1 list, i. e. a 1-cell, 12 15 18 21
the result is a list of 2 48 51 54 57
1-cells, i. e. an array of
shape 2 4
Figure 5. Execution of +/"2 i. 2 3 4
+/"3 i. 2 3 4
12 14 16 18
20 22 24 26
28 30 32 34
The verb is applied to the single 3-cell. Its items, which are 2-cells, are added, leaving a
single 2-cell as the result.
How about i."0 (2 2 2)—can you figure out what that will produce? (Notice I
put parentheses around the numeric list 2 2 2 so that the rank 0 wouldn't be treated as
part of the list)

39
Other documents randomly have
different content
The Project Gutenberg eBook of Mademoiselle
de Bressier
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: Mademoiselle de Bressier

Author: Albert Delpit

Release date: June 27, 2013 [eBook #43047]


Most recently updated: October 23, 2024

Language: French

Credits: Produced by Clarity, Hélène de Mink, and the Online


Distributed Proofreading Team at http://www.pgdp.net
(This
file was produced from images generously made
available
by The Internet Archive/Canadian Libraries)

*** START OF THE PROJECT GUTENBERG EBOOK MADEMOISELLE


DE BRESSIER ***
Note sur la transcription: Les erreurs clairement
introduites par le typographe ont été corrigées.
L'orthographe d'origine a été conservée et n'a pas été
harmonisée. Les numéros des pages blanches n'ont pas
été repris.

Mademoiselle
de Bressier
PAR

ALBERT DELPIT

.... Une guerre encore plus que


civile, une cité grande entre les
cités, tournant d'une main furieuse
le fer des siens contre son
cœur!
(Lucain: La Pharsale).

DEUXIÈME ÉDITION
PARIS
PAUL OLLENDORFF, ÉDITEUR

28 bis, RUE DE RICHELIEU, 28 bis

1886

Tous droits réservés

IL A ÉTÉ TIRÉ DE CET OUVRAGE:


Cinquante exemplaires numérotés à la presse

20 exemplaires sur papier du Japon 1 à 20


30 exemplaires sur papier de Hollande 21 à 50

A MON CONFRÈRE ET AMI


FRANCIS MAGNARD
Février 1886.
PREMIÈRE PARTIE
..... Une guerre encore plus
que civile, une cité grande
entre les cités, tournant d'une
main furieuse le fer des siens
contre son cœur!
(Lucain: La Pharsale.)
PREMIÈRE PARTIE

Le bataillon défilait lentement le long de la rue de Rivoli; en tête, le


drapeau rouge, suivi d'une musique criarde. Peu de monde aux
fenêtres. A peine quelques curieux, çà et là, les mains dans les
poches, regardant ces hommes qui s'en allaient à la boucherie. Une
petite vendeuse de violettes, adossée contre un magasin, ouvrait ses
yeux étonnés, pendant qu'un marchand grommelait tout bas «contre
ces gens qui empêchaient les affaires de marcher». De temps en
temps passait un officier, au visage rouge, aux paupières injectées,
engoncé dans son uniforme galonné. Il disparaissait vite par une rue
latérale, poursuivi par des gamins qui criaient. Les promeneurs, très
rares, pressaient le pas, vaguement inquiets. Chez les soldats, rien
de ce qui relève le moral d'hommes marchant au combat. Tristes,
sombres, muets, ils allaient, le front baissé, n'osant pas se regarder
les uns les autres, comme si chacun craignait de voir dans les yeux
de son voisin le reflet de ses terreurs lugubres.
Au loin, on battait la générale. Un roulement sourd, adouci par la
distance, avec quelque chose de funèbre et d'alangui. On eût dit le
rappel des condamnés. Et c'étaient des condamnés, en effet, forcés
de défendre une cause perdue. Un voile de mélancolie semblait
épandu sur la cité, flottant sur les fronts et les consciences. Tout ce
monde portait le deuil de quelqu'un ou de quelque chose: peut-être
d'un espoir écroulé.
A quelque distance de l'Hôtel de ville, une centaine d'hommes se
joignaient au bataillon. Des enragés, ceux-là, trompés sans doute
par les proclamations menteuses de la Commune. Il suffisait de voir
leur mine conquérante, leurs yeux brillants, leurs fusils très soignés
dont le canon d'acier reluisait au soleil. Ils croyaient sérieusement au
patriotisme des braillards de clubs; ils croyaient au courage de ceux
qui les envoyaient se battre, pendant que certains chefs restaient à
l'abri. Il y avait de tout dans cette troupe, décidée à vaincre ou à
mourir: des exaltés, grisés par la pensée d'un sacrifice sublime; des
égarés, qu'affolaient encore les souffrances physiques et morales du
premier siège; surtout, cette écume populacière que les révolutions
rejettent sur le pavé des rues, écume noire, pareille à la boue qui
surnage à la surface des grands fleuves troublés.
Ils se représentaient l'armée de Versailles à moitié vaincue. Elle
s'évanouirait du jour au lendemain, ainsi que les vapeurs grisâtres
dissipées par le premier rayon de soleil. Ils riaient, ils chantaient,
essayant d'égayer la tristesse de leurs compagnons. Mais bientôt, le
découragement des autres les gagnait, les enveloppait, de même
qu'un lumineux coteau est assombri bien vite par les brouillards
montant de la vallée.
Le bataillon s'arrêta sur la place de la Concorde. Elle se couvrait de
soldats. Il en venait de droite, de gauche, par le pont, par le quai,
par la rue Royale, et l'avenue Gabriel. Là encore, un dédaigneux
abandon. Pas de foule. Les promeneurs ne détournaient point la
tête. Les bonnes d'enfants ne s'attardaient plus; elles ne montraient
pas aux petits curieux la troupe «de ces militaires», moins placides
que les troupiers bonasses.
Cependant, les hommes mettaient la crosse en terre. On
commençait l'appel. Les uns et les autres s'étiraient, comme déjà
lassés par cette première étape: puis chacun répondait: «Présent!»
ou un silence de quelques minutes suivait le nom prononcé. Les
absences ne pouvaient guère surprendre. Après six mois de siège, et
deux mois de guerre civile, les vides se faisaient nombreux, par la
faim, par la fièvre, par la maladie qui décimait les pauvres. On ne
comptait même plus ceux qui manquaient. L'homme prend l'habitude
de tout, même de la souffrance et du danger.
Tout à coup, le capitaine d'une compagnie appela: «Pierre Rosny!»
Et comme personne ne répliquait, il ajouta d'un ton surpris:
—Comment, Pierre Rosny n'est pas là?
Un garde national sortit du rang.
—Pierre nous rejoindra au Point-du-Jour, citoyen. Il a une
consultation ce matin pour son fils.
Invoquée pour un autre, cette excuse eût soulevé les rires et les
quolibets. Mais il s'agissait de Rosny. Personne ne broncha. C'était
un homme convaincu et brave, ayant fait dix fois ses preuves. Nul ne
se serait permis de douter de lui. S'il n'était pas venu, c'est qu'il ne
pouvait pas venir. On ne suspectait ni la bonne volonté ni le courage
de celui-là. Pendant une heure, ce fut une suite ininterrompue de
commandements, de contre-ordres, d'appels. Des officiers passaient
ventre à terre, s'éloignant dans la direction de la rue Royale; les
cantinières allaient d'escouade en escouade, offrant un petit verre
d'eau-de-vie rarement refusé. Mais les conversations se faisaient
plus rares. Nulle part, on ne sentait l'entrain des premiers jours. Une
immense lassitude, qui touchait presque au dégoût, alanguissait les
cœurs et les volontés.
Enfin douze batteries d'artillerie parurent, sortant des Tuileries,
traînées au grand trot par des chevaux vigoureux. Ce fut un
roulement de tonnerre, pendant que les canons filaient le long des
Champs-Élysées, leurs gueules de bronze tournées vers ce Paris
qu'elles voulaient défendre. Un homme grand, sec, habillé d'une
longue redingote noire, fit quelques pas sur la chaussée, jetant un
regard aigu sur les bataillons rangés. Il inclinait un peu la tête en
marchant, comme si elle eût plié sous le poids d'une responsabilité
trop lourde. L'œil, fixe et brillant, s'illuminait par instants de rapides
éclairs. On sentait là une volonté qui pensait. Un léger tressaillement
nerveux secouait le bas du visage. Alors les lèvres minces et pâles
s'entr'ouvraient, montrant des dents très blanches. Cet homme était
le citoyen Delescluze, délégué à la guerre. Il monta sur un banc et
leva la main. Tous les bataillons s'ébranlèrent les uns après les
autres dans un ordre remarquable. A force de se battre, ces ouvriers
devenaient des soldats. Puis, sous la volonté puissante de ce révolté,
ils sentaient mollir les vieilles rébellions toujours prêtes à bondir
dans leurs âmes. La longue file noire s'engagea dans l'avenue des
Champs-Élysées où le soleil de mai jetait d'éblouissantes nappes de
lumière. L'artillerie semblait plus menaçante parmi cet appareil
guerrier, dans ce gai retour du gai printemps. Le ciel bleu riait, la
brise tiédie embaumait; les arbres exilés au Rond-Point des Champs-
Élysées et au Cours-la-Reine, pouvaient se croire encore dans la
profondeur sombre de la forêt natale. «Mai qui fleurit, cœur qui rit»,
dit la chanson. Les cœurs gémissaient cependant, les yeux
pleuraient, et là-bas, dans la grande ville, saignait l'immense
troupeau des veuves et des orphelins.
Ce n'était pas fini. La Commune concevait le rêve tragique de
s'ensevelir sous les ruines fumantes de Paris. Furieusement, elle
poussait ces hommes au combat; ils croyaient mourir pour une Idée,
et ne tombaient que pour assouvir l'ambition effrénée de quelques-
uns. On racontait que ce jour-là l'armée des rebelles tentait une
grande sortie: la sortie de malheureux poussés par des chimères et
se ruant vers l'Impossible.
Les pavés de Paris s'entr'ouvraient pour vomir des bataillons. De la
Bastille à l'Arc-de-Triomphe, montait une foule énorme, remuante,
sombre à l'œil. Ondulante et secouée comme un serpent
gigantesque, elle déroulait ses anneaux d'acier d'où sortaient des
canons de fusil et des baïonnettes aux reflets sinistres. Mais à la
Bastille, les bataillons ne s'embrigadaient pas comme aux Champs-
Élysées. Ceux de ce quartier-là formaient l'arrière-garde. Ainsi, dans
la rue Jean Baussire qui se tord sur elle-même pour aller du
boulevard Beaumarchais à la place, c'étaient des allées et venues
sans fin. A la porte d'un petit pharmacien, situé vers le milieu de la
rue à côté d'un hôtel borgne, une longue file stationnait, impatiente
et souffreteuse. On faisait queue pour les médicaments, maintenant,
comme naguère pour le pain et pour la viande. Le pharmacien se
hâtait et se démenait, ne sachant où donner de la tête. Aidé de ses
deux élèves, il préparait hâtivement les ordonnances, sans intérêt,
sans pitié pour les malades, qui attendaient de lui la guérison. A
peine eut-il un geste d'empressement, quand un garde national
entra, disant:
—La potion est-elle prête?
—Voilà, citoyen Rosny.
Le citoyen Rosny était un homme de quarante ans, grand, brun,
pâle, d'une figure énergique. Il prit délicatement la fiole entre ses
mains calleuses, avec un soin infini, comme s'il craignait de la briser.
Il balbutia un remerciement furtif, puis, sortant de la pharmacie,
traversa rapidement la rue. Il entra dans une maison triste
d'apparence et noircie par le temps. En guise de porte, une cloison
disjointe suintant l'humidité. L'étroit escalier conduisait à des
chambres pauvres occupées par des ouvriers vivant au jour le jour.
Qui donc parmi ces malheureux possédait encore des économies
après les épreuves de ces mois terribles? Au cinquième étage, le
citoyen Rosny s'arrêta et frappa contre une porte, en disant très bas:
«C'est moi, Françoise.» La porte s'entre-bâilla et se referma
rapidement, pendant que Françoise répliquait, également à voix
basse: «Prends garde. Il ne faut pas changer la température.» La
chambre était petite, mais très propre; les murs nus et reluisants, les
rideaux éblouissants, les carreaux vierges attestaient des soins de
tous les instants.
—Comment est Jacques? continua Pierre sur le même ton.
—Toujours calme.
Et la jeune femme, en disant ces deux mots, couvait d'un ardent
regard un garçon de seize ans qui sommeillait, étendu dans le lit.
Les yeux du père et de la mère se rencontrèrent dans une commune
pensée. Françoise embrassa tendrement son mari:
—Voyons, ne te tourmente pas, reprit-elle. Le docteur est certain
que tout danger a disparu. Tu sais bien qu'il amène aujourd'hui son
maître, un grand savant. Ah! je suis plus inquiète de toi que de
Jacques, va, maintenant!
Avec une expression de haine farouche, elle étendait son poing
fermé dans le vide, comme pour en menacer des ennemis lointains.
Elle était belle ainsi, dans l'éclat de ses trente-cinq ans, avec sa
crinière blonde qui donnait un caractère étrange à sa figure d'une
pâleur mate. Cette fille du peuple avait l'élégance innée. Grande,
bien faite, elle semblait créée pour le luxe; ses yeux d'un bleu très
sombre, étincelaient; le front haut, un peu bombé au-dessus des
tempes, prouvait l'intelligence, et le regard révélait une énergie
vaillante. Pierre Rosny oubliait l'enfant pour une minute. Maintenant
il contemplait sa femme avec une expression de tendresse fière.
Françoise réveilla son malade, et lui fit boire une gorgée de potion.
—Comment es-tu, Jacques?
—Bien, maman. Merci.
—As-tu encore sommeil?
L'enfant sourit:
—J'ai toujours sommeil, murmura-t-il.
Il ferma de nouveau les yeux, pendant qu'elle le baisait au front.
Puis, bordant avec soin la couverture, elle revint auprès de son mari,
qu'elle entraîna dans un coin de la chambre.
—Tu partiras après la visite du docteur?
—Oui, j'ai fait avertir le capitaine que je rejoindrais le bataillon au
Point-du-Jour. Oh! j'ai le temps.
Françoise hésitait. Elle reprit:
—Tu crois que c'est pour aujourd'hui la grande sortie?
—Pour aujourd'hui ou pour demain. En tous cas, je resterai peut-être
deux jours dehors. Il faut en finir, tu comprends. Ça ne peut pas
durer toujours. Et encore, Dieu sait quand je retrouverai du travail!
Après la guerre, les maçons, les menuisiers auront de l'ouvrage: il y
a tant de maisons par terre, et tant de ruines à relever! Mais nous
autres, les compositeurs d'imprimerie! Si c'est la Commune qui
l'emporte: bon. Et puis, il y aura toujours les trente sous par jour.
Mais si ce sont les autres? Tu sais bien ce qu'on nous raconte. A
Versailles, ils veulent faire la monarchie, et une monarchie comme
avant 89; c'est-à-dire plus de Chambre, plus de libertés, plus de
journaux. On cassera les presses, et personne n'aura le droit d'être
imprimeur. Si on supprime les journaux, on ne permettra pas les
livres non plus. Pense donc! Une censure comme autrefois! Alors,
qu'est-ce que nous deviendrons, nous autres, les compositeurs? Tu
vois bien que j'ai raison de me mettre en colère et de désespérer.
Cet homme intelligent, presque instruit, qui avait beaucoup lu Jean-
Jacques, débitait sérieusement ces balourdises énormes. Il croyait
aux mensonges des clubs, aux calomnies de quatre ou cinq feuilles
publiques. Comme tant d'autres fédérés, il s'imaginait que des
bandes de chouans marchaient sur Paris. La folie faisait délirer ce
cerveau, de même que déliraient aussi d'autres cerveaux moins
solides. Il avait eu des succès dans les réunions publiques avec son
élocution facile et un peu déclamatoire. Ces applaudissements
faisaient de lui un sectaire, un fanatique. Tous ses amis se jetaient
dans le mouvement insurrectionnel, et il les suivait naturellement.
—C'est effrayant, tout ce que tu me dis là. Et tu admets que l'ancien
régime pourrait revenir?
—Il faut bien le croire, puisqu'on nous l'affirme. Est-ce que tu
t'imagines qu'on se battrait, s'il ne fallait pas sauver la Liberté?
Françoise cachait sa tête pâle entre ses mains. Ses cheveux blonds,
mal retenus par le peigne, tombaient maintenant sur ses épaules, et
la jeune femme s'auréolait d'une splendeur fauve. Elle reprit,
haussant la voix, avec un geste brusque:
—Si ce que tu racontes est vrai, c'est nous qui serons les vainqueurs.
On ne recommence jamais le passé. Ce qui est fini est fini. Est-ce
qu'une barque remonterait le courant de la Seine? Je ne peux pas
croire aux folies qu'on débite. Supprimer toutes les libertés!
Comment vivrait le pauvre monde? Il y a des moments où je
m'imagine qu'on colporte ces histoires-là, pour que, vous autres,
vous ayez du cœur à vous battre. Du moment que tu me dis que
c'est vrai, toi, un honnête homme, c'est bien, je te crois. Alors, c'est
moi qui ai raison. Nous l'emporterons. Et nous l'emporterons, parce
que nous avons pour nous le bon droit et le bon sens.
—Ma brave Françoise!
—Et puis, nous ne pouvons pas avoir donné pour rien nos larmes et
notre sang! Ah! ce que j'ai peur, vois-tu! Tu vas retourner là-bas... Et
si tu ne revenais pas?
Dans un mouvement de passion, elle se jetait dans les bras de
Pierre, collant ses lèvres à celles de son mari. Elle l'aimait tant! Ils se
rencontraient un jour, dans un square, ils causaient ensemble
pendant une heure, et se plaisaient tout de suite. Lui, vingt-deux
ans; elle, seize. La liaison s'ébauchait rapidement. Vers le milieu de
la journée, il disait «mademoiselle Françoise»; et elle l'appelait
«monsieur Pierre». Ils se racontaient leur histoire commune, avec la
confiance touchante et sublime des êtres bons.
Lui, travaillait dans une imprimerie. Un bon métier: il gagnait huit
francs par jour. Mais, par exemple, il ne fallait pas bouder à la
besogne. Son patron l'estimait; il espérait bien être un jour metteur
en pages dans un journal. Oh! alors, il deviendrait riche, il aurait vite
des économies. Cette bambine de seize ans se montrait ravie d'en
apprendre si long. Ce qui touche à l'imprimerie comme ce qui touche
au théâtre, intéresse toujours les êtres intelligents. L'un et l'autre ne
servent-ils pas à grandir et à exalter la pensée humaine?
A son tour, Françoise parlait d'elle. Elle était dans un atelier de
couture, appartenant aux célèbres demoiselles Standisch. De même
que Pierre, elle donnait des détails amusants, racontant les niches
que se faisaient les ouvrières, les bavardages de celle-ci, les amours
de celle-là. Pierre s'égayait:
—Est-ce que vous avez aussi des amoureux, mademoiselle
Françoise?
—Moi? jamais! répliquait la jeune fille, en le regardant bien en face,
de ses yeux purs et tranquilles. Mon parti est pris. Je veux me
marier, aimer mon mari, avoir un enfant. Voyez-vous, monsieur
Pierre, il y a celles qui sont honnêtes et celles qui ne le sont point.
On ne peut pas se montrer coquette et rester sage. On ne joue pas
avec l'amour d'un honnête homme. Si on l'aime, il faut le lui dire, et
si on le lui dit, il faut l'épouser.
Les jeunes gens se quittaient, charmés l'un de l'autre. Ils se
revoyaient le dimanche suivant; et, peu à peu, Pierre apprenait à
estimer Françoise, à l'aimer davantage. Le compositeur jugeait bien
vite son caractère. Elle était absolument droite, foncièrement loyale;
en revanche, violente et passionnée. Elle haïssait «les bourgeois»:
ce qu'elle appelait les «gens qui se sont seulement donné la peine
de naître»! Pourquoi cette exaltation absurde chez une créature
honnête qui jugeait sainement les choses? Sans doute le reflet d'une
éducation première, l'enseignement d'une mère envieuse et jalouse.
Peu importait ce mauvais grain, jeté par hasard dans une si bonne
terre. Tant de qualités faisaient oublier ce défaut-là! Courageuse,
active, ne reculant jamais devant la fatigue, et disant d'une certaine
façon: «Cela est bien» ou «Cela est mal», qui faisait comprendre
tout de suite que cette enfant de seize ans irait droit dans la vie,
sans dévier jamais du chemin du devoir et de l'honneur. Deux mois
après, ils s'épousaient. Neuf mois, jour pour jour, après le mariage,
Jacques venait au monde. Et dès lors, ils vivaient tous les trois,
heureux et fiers. Après dix-sept ans de labeurs et de soins, le
ménage économisait enfin quelque argent. En mai 1870, il possédait
4,000 francs à la caisse d'épargne. Dans le quartier,—ils demeuraient
alors rue Saint-Antoine,—tout le monde aimait ces braves gens, si
beaux, si bons, si travailleurs. Puis la guerre éclatait, et Jacques
devenait garde national. Il entrait dans les bataillons de marche, car
il voulait se battre. Et il se battait bien, aux avant-postes, du côté du
fort de Montrouge. Mais plus de travail, plus de gain. On commençait
de manger les économies; le bon temps était passé, et le malheur
allait venir.
Assise auprès du lit, Françoise évoquait tous ces souvenirs, et des
larmes coulaient de ses yeux. Vrai, depuis quelques mois, elle payait
bien son bonheur passé. Au 18 mars, voilà que Pierre se jetait dans
la Commune! Elle n'osait pas le retenir, croyant qu'il faisait ce qu'il
devait faire. Alors recommençaient les éternelles angoisses. Les deux
seuls êtres qu'elle aimât, toujours en péril!
Cependant, Jacques se rendormait. Le mari et la femme se
rapprochaient de la fenêtre et causaient encore, mais à voix très
basse pour ne pas éveiller l'enfant. Pierre dit pour la seconde fois:
—Vrai, tu n'es plus inquiète de Jacques?
—Non. Malheureusement, les forces sont lentes à revenir.
A dix heures seulement, le docteur parut, accompagné d'un autre
homme de haute taille, à l'œil vif, au front puissant. C'était le
docteur Grandier, médecin en chef des hôpitaux, un savant illustre;
mieux qu'un homme illustre: un homme très bon. Il salua
respectueusement Françoise et hocha la tête, mécontent, en voyant
la vareuse de garde national sur le dos de Pierre. Enfin, se tournant
vers son jeune collègue, un de ses anciens internes:
—Alors, vous me disiez, Borel?...
—Je vous disais, mon cher maître, que ce jeune garçon revient de
loin. Une balle dans le corps, rien que ça!
—Une balle... par accident?
—Non pas, s'il vous plaît, mon cher maître! Un joli lingot de plomb,
en pleine poitrine, à Montretout.
M. Grandier restait stupéfait. Il regardait Pierre et Françoise comme
s'il les prenait pour des fous.
—C'est votre fils, n'est-ce pas, Madame? Vous êtes assez jolie et
assez jeune pour que je vous adresse cette question.
—Oui, Monsieur, répliqua-t-elle, rougissant un peu.
—Mais c'est un bambin! quel âge a-t-il?
—Seize ans et demi.
—Et vous le laissez s'engager? Vous êtes bons tous les deux à
mettre à Charenton!
—Oh! il est parti malgré moi, répliqua Françoise, en ébauchant un
vague sourire de fierté. Son père, mon mari que vous voyez là, se
battait aux avant-postes, pendant le premier siège. Moi, je restais
seule avec Jacques. L'enfant devenait triste. Il ne se plaisait même
plus à pétrir de la terre glaise. Car c'est un artiste, Monsieur! Il usait
ses journées à regarder les troupes défiler, et il fermait les poings
d'un air sombre. Un matin, il m'a dit: «C'est honteux de penser que
je suis ici à ne rien faire, quand les autres se battent!» Je demeurais
tout interdite, toute frissonnante. Pensez donc! je tremblais déjà
pour mon mari. Est-ce que j'allais encore trembler pour mon fils?
«Mais tu es trop petit, Jacques. Il n'y a pas un seul bataillon où on
voudrait de toi!» Il m'a répondu, en hochant la tête: «Alors,
pourquoi père me racontait-il autrefois de si belles histoires? Celle de
Bara, tambour à quatorze ans; celle des volontaires de seize ans, qui
s'enrôlaient pour courir à la frontière?» Je ne savais trop que
répliquer. On a tort de mettre certaines idées dans le cerveau des
enfants. Pendant huit jours encore, Jacques restait songeur, tout
triste. Il rentrait tard, le soir. Un matin, il m'a dit: «Écoute, maman,
je voudrais t'obéir, mais il n'y a plus moyen. Bersier... tu sais, Bersier,
le graveur qui m'a appris à dessiner? eh bien, il est sergent dans les
francs-tireurs. Il m'a fait inscrire dans sa compagnie. Je partirai
tantôt. Pardonne-moi, maman! mais je n'y tenais plus!» Et il me
sautait au cou, m'embrassant, me câlinant. Moi, j'étais bien
malheureuse, mais aussi toute fière! Oh! je peux dire cela, Jacques
dort, il ne m'entend pas. Il y a une âme de héros et d'artiste dans
cet enfant. J'ai souri; et j'ai répondu: «Va te battre, puisque tu y
tiens tant que ça!» Mais après son départ, je me suis mise à
sangloter; je maudissais le sort. Ah! que je souffrais, quand la nuit
tombait toute noire, toute glacée! Je pensais à mon pauvre petit,
déjà intelligent, fier et hardi comme un homme. Quinze jours après,
on se battait à Montretout. Jacques sautait le premier dans le jardin
de M. Gounod, où se cachaient six cents Badois. Et il tombait, la
poitrine traversée. Voilà notre histoire, Monsieur.
Françoise parlait simplement, avec une émotion concentrée, mais
profonde. Elle jetait sur Jacques un long regard chargé d'amour. Le
petit héros dormait toujours, et son sommeil souriait. Peut-être
rêvait-il fièrement aux belles actions accomplies. M. Grandier
détournait la tête. Il ne voulait pas laisser voir les larmes qui
roulaient dans ses yeux. Rien ne remue un homme de cœur comme
la rencontre soudaine d'un caractère. Les êtres supérieurs ont plaisir
à rencontrer la supériorité chez les autres.
—Voulez-vous me donner la main, Monsieur? dit-il en se tournant
vers Pierre Rosny. L'homme et la femme qui ont mis au monde et qui
ont élevé cet enfant-là sont de braves gens.
—Vous nous le guérirez, n'est-ce pas, docteur? s'écria Pierre dans un
élan de reconnaissance.
M. Grandier souriait maintenant.
—Laissez-moi le voir d'abord, que diable! répliqua-t-il avec sa
bonhomie charmante. Bien sûr, on le guérira. Il n'y a pas déjà tant
de Français comme votre petit! D'ailleurs, Borel s'y connaît. S'il
répond de son malade, c'est que tout va bien.
L'illustre médecin s'asseyait près du lit, et réveillait Jacques
doucement. Le blessé ouvrait les yeux et regardait avec confiance la
figure du savant où rayonnait la bonté.
—C'est le maître du docteur, Jacques.
—Bonjour, monsieur Borel, dit le jeune garçon en tendant la main au
médecin, devenu son ami.
Puis, il reportait les yeux sur M. Grandier qui l'étudiait maintenant
avec son regard pénétrant de psychologue. Il avait les cheveux
blonds de sa mère; et, comme elle aussi, des yeux d'un bleu
sombre, fiers, passionnés et résolus. Il tenait entièrement de
Françoise. On eût dit que l'âme de cette femme était entrée dans le
corps de cet enfant. Le visage, pâli par la souffrance, par les longues
semaines passées au lit, s'amincissait au menton, accusant une
finesse énergique. Les lèvres se dessinaient très nettement: signe de
volonté et de courage. Quant au front, il apparaissait large et
puissant sous les cheveux blonds.
—Borel a raison, pensait M. Grandier. Il y a là un homme.
Il continua, reprenant son sourire bienveillant:
—Mon cher enfant, je vais examiner votre plaie.
—Merci, Monsieur. Si vous saviez comme M. Borel a été bon pour
moi!
—Allons, Jacques, tais-toi! répliqua celui-ci.
—Non, je ne me tairai pas! Vous avez été bon, très bon. Sans vous,
je serais mort dix fois. Je suis heureux de le dire et de le répéter. Je
serai heureux de m'en souvenir, surtout.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like