mean=: +/ % # mean 2 3 4 5 6 4 (geomean=: # %: */) 2 3 4 5 6 3.72792由於程式 mean 為一新的動詞,通常稱句子類似 mean=: +/ % # 為動詞定義 (或定義), 而結果得到的動詞稱之為定義過的動詞,或函數。
MEAN=: sum % # sum=: +/ MEAN 2 3 4 5 6 4動詞本身 (不含引數)顯示其定義,外部連接詞(!:)可以用來描述顯適的格式:封裝、樹狀、線型或括號。 (執行J時也可以設定動詞顯示形式, 在選單項目 Edit|Configure...|View.) 因此:
mean +/ % # 9!:3 (2 4 5) mean +-----+-+-+ |+-+-+|%|#| ||+|/|| | | |+-+-+| | | +-----+-+-+ +- / --- + --+- % +- # +/ % #
練習
6.1 | Enter AT=: i. +/ i. and use expressions such
as AT 5 to determine behaviour of program AT . |
6.2 | Define與use similar 函數表 for or 雙邊函數. |
6.3 | Define programs:
tab=: +/ ft=: i. tab i. test1=: ft = ATn apply test1 to 各類整數引數to test proposition that ft 同於 AT of Exercise 6.1, and enter ft and AT alone to display ir定義. |
6.4 | Define aft=: ft f. and use test2=: aft = ft to test
ir equivalence. n display ir定義與state effect
of 副詞 f. . 解答:副詞 f. fixes 動詞 to which it applies, replacing each name used by its定義. |
6.5 | Redefine tab of Exercise 6.3 by
entering tab=: */ and observe effects on ft
and its fixed alternative aft . |
6.6 | Define mean=: +/ % # and state its behaviour when applied
to a 表格, as in mean t=: (i. !/ i.) 5 . 解答:result is average of, not over, rows of a表格引數. |
6.7 | Write an expression for mean of columns
of t . 解答: mean |: t or mean"1 t |