Guides/Language FAQ/Sentence Train

From J Wiki
Jump to navigation Jump to search

Why Does "+/ *: a work", but when I say "foo =: +/ *:", then "foo a" it doesn't work?

You have

   +/ *: 1 2 3
14

but when you make a verb to do the operation, you get

   foo =: +/ *:
   foo 1 2 3
2 5 10
3 6 11
4 7 12

What happened?

The complete story is a bit intricate, but you can get along quite well to begin with by imagining that the name of a verb is replaced by its value enclosed in parentheses. This is similar to mathematics, where if you want to substitute into you have to write rather than .

So, when you used your foo, it was as if you had written (+/ *) 1 2 3 which would give you:

   (+/ *:) 1 2 3
2 5 10
3 6 11
4 7 12

We needn't concern ourselves with what (+/ *:) does (it's called a hook); all we need to know now is that it's not the same as +/ *: without the parentheses.

Correct ways to write foo are:

   foo =: 3 : '+/ *: y'
   foo =: 13 : '+/ *: y'
   foo =: verb : '+/ *: y'
   foo =: +/@:*:
   foo =: [: +/ *:

It should be noted that the notion that a verb is replaced by its parenthesized value is fundamentally incorrect. That is just a way of thinking about the execution of a sentence that gets the correct result in normal cases. The actual processing is different, as described in the references.

See Also


Contributed by HenryRich