J uses parentheses for punctuation, together with the
following rules for unparenthesized phrases:
The right argument of a verb is the value of
the entire phrase to its right.
Adverbs are applied first. Thus, the phrase a */ b
is equivalent to a (*/) b, not to a(*/b).
For example:
a=:5 b=:3 (a*a)+(b*b) 34 a*a+b*b 70 a*(a+(b*b)) 70 (a+b)*(a-b) 16 a (+*-) b 16The last sentence above includes the isolated phrase +*- which has thus far not been assigned a meaning. It is called a trident or fork, and is equivalent to the sentence that precedes it.
c=:2 3 4 5 6 (+/ % #) c The verb # yields the number of items in its argument 4 (+/c)%(#c) 4
Exercises
4.1 | In math, the expression 3x4+4x3+5x2 is called a polynomial.
Enter: x=: 2 (3*x^4)+(4*x^3)+(5*x^2)to evaluate the polynomial for the case where x is 2. |
4.2 | Note that the hierarchy among functions used in math
is such that no parentheses are necessary in writing a polynomial.
Write an equivalent sentence using no parentheses. Answer: +/3 4 5 * x ^ 4 3 2 or (first assigning names to the coefficients 3 4 5 and the exponents 4 3 2), as: +/c*x^e |