>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  Help  Dictionary

6. Programs

A program handed out at a musical evening describes the sequence of musical pieces to be performed. As suggested by its roots gram and pro, a program is something written in advance of the events it prescribes.

Similarly, the fork +/ % # of the preceding section is a program that prescribes the computation of the mean of its argument when it is applied, as in the sentence (+/%#)b. However, we would not normally call the procedure a program until we assign a name to it, as illustrated below:
   mean=: +/ % #
   mean 2 3 4 5 6

   (geomean=: # %: */) 2 3 4 5 6
Since the program mean is a new verb, we also refer to a sentence such as mean=: +/ % # as verb definition (or definition), and to the resulting verb as a defined verb or function.

Defined verbs can be used in the definition of further verbs in a manner sometimes referred to as structured programming. For example:
   MEAN=: sum % #
   sum=: +/
   MEAN 2 3 4 5 6
Entry of a verb alone (without an argument) displays its definition, and the foreign conjunction (!:) can be used to specify the form of the display: boxed, tree, linear, or parens. (The session can also be configured to specify the form of verb display, under the menu item Edit|Configure...|View.) Thus:
+/ % #

   9!:3 (2 4 5)
||+|/|| | |
|+-+-+| | |
  +- / --- +
--+- %      
  +- #    
+/ % #


6.1   Enter AT=: i. +/ i. and use expressions such as AT 5 to determine the behaviour of the program AT .

6.2   Define and use similar function tables for other dyadic functions.

6.3   Define the programs:
   tab=: +/
   ft=: i. tab i.
   test1=: ft = AT
Then apply test1 to various integer arguments to test the proposition that ft is equivalent to AT of Exercise 6.1, and enter ft and AT alone to display their definitions.

6.4   Define aft=: ft f. and use test2=: aft = ft to test their equivalence. Then display their definitions and state the effect of the adverb f. .

Answer: The adverb f. fixes the verb to which it applies, replacing each name used by its definition.

6.5   Redefine tab of Exercise 6.3 by entering tab=: */ and observe the effects on ft and its fixed alternative aft .

6.6   Define mean=: +/ % # and state its behaviour when applied to a table, as in mean t=: (i. !/ i.) 5 .

Answer: The result is the average of, not over, the rows of a table argument.

6.7   Write an expression for the mean of the columns of t .

Answer: mean |: t or mean"1 t

>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  Help  Dictionary