User:Raul Miller/JForNonJUsers

From J Wiki
Jump to navigation Jump to search

Notes on aspects of J which might be notable from the viewpoint of a programmer who has little or no familiarity with J.

In some other programming language, you might see something like

f1(); f2(3, -4, 5);

In many languages the ';' character represents the end of some sentences. In J, a sentence corresponds to a single line, and the end of the line marks the end of the sentence. In other words, J is a command-line language, and is designed to be used interactively in a portable fashion.

In many languages, function calls are represented by the presence of a set of parenthesis which delimits the argument list for that function. In J, argument lists are just the same as any other list and the parenthesis are optional. So J function calls are represented by the presence of arguments. The empty character list is often used to serve the role of an empty argument list.

In J, numbers may includes spaces (for example, the list of three numbers 1 2 3 is treated as a single word in J.) The only other words in J which may contain spaces are quoted strings ('like this') and comments (NB. like this).

Because - is a token (and for some other reasons), J needs some other way to represent negative numbers within a list. J uses a leading underline character for this purpose (_1 is negative one). A superscript minus would look better, but that is not portably supported on the current generation of computers.

Thus, the above example might be represented in J as

f1 f2 3 _4 5

However, more verbose representations are also viable:

f1() f2(3, _4, 5)

or even

f1 ( ) f2 ( 3 , ( - 4 ) , 5 )

A fundamental characteristic of J data is its "shape". "Shape" means the length of a list, the length of the items in the list and so on in a sort of recursive sense. For example, a four by four square matrix would have the shape 4 4. Here, the matrix has four items (the first number in the list). A four row matrix with only three columns would have the shape 4 3. Note that both of those shapes are themselves lists -- each of those shapes themselves have the shape 2.

Data with no particular structure (for example, the number 1) have an empty shape.

[fixme: need to focus more on examples and less on abstractions.]