Guides/Language FAQ/Constant List

From J Wiki
Jump to navigation Jump to search

"1 2 3" makes a list of numbers, why doesn't "a b c" do that when they are all numeric?

J beginners, learning that 1 2 3 is a 3-element vector of numbers, often reach the erroneous conclusion that space is a concatenation operator in J, and that two nouns appearing side-by-side are concatenated. They are then surprised by

   1 2 3  NB. create a list
1 2 3
   a =: 1
   b =: 2
   c =: 3
   a b c  NB. Why doesn't this create the same list?
|syntax error
|       a b c

Space is not a concatenation operator. , (comma) is the concatenation verb. Lists of consecutive numbers are a special case. They are recognized during the initial analysis of a sentence, before execution begins. a b c can't be recognized at that point, because the values of a, b, and c may change during execution of the sentence.

Contributed by HenryRich