Space

From J Wiki
< Help(Redirected from Help/Primer/Space)
Jump to navigation Jump to search


<=   =>

Spaces are not required to separate primitives from other words. On the other hand extra spaces don't change the meaning.

   2+3
5
   2 + 3
5
   2    +    3
5


Most examples in this book have spaces around all primitives. This makes the individual words stand out and allows you to concentrate on the meaning of the words without the additional problem of first figuring out what the words are.

However, most J programmers, as they become more experienced, reach a point where they can easily read the words in a sentence, and the extra spaces become a nuisance and hindrance to understanding, rather than an aid. You will notice that in some of the later examples that some of these unnecessary spaces are left out.

There are some cases where a space is essential.

A space must separate names.

   a=.3
   plus=.+
   a plus a
6
   aplusa
|value error: aplusa


The . (dot) and : (colon), used as inflections, change the word immediately in front of them into a new word. When used as a primitive or as the start of a primitive, they must have a space in front so that they are not treated as an inflection.

   ;: 'a . b'	NB. 3 words
+-+-+-+
|a|.|b|
+-+-+-+
   ;: 'a .b'	NB. same 3 words
+-+-+-+
|a|.|b|
+-+-+-+
   ;: 'a. b'	NB. 2 words
+--+-+
|a.|b|
+--+-+


A space must separate a . or : , that is not being used as an inflection, from the previous word.

Numbers, for example 1e7, can contain letters. There are in fact several letters that can be used in spelling numbers in J. Letters that immediately follow a number are treated as part of the spelling of the number.

   plus =. +
   1plus 3
|ill-formed number
|      1plus 3
|      ^
   1 plus 3
4


A space must separate a number from a letter that is not a part of the number.

<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106