>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Dictionary

7. Bond Conjunction
A dyad such as`^` can be used to provide a family of monadic functions:

       ]b=: i.7
    0 1 2 3 4 5 6

       b^2                        Squares
    0 1 4 9 16 25 36

       b^3                        Cubes
    0 1 8 27 64 125 216

       b^0.5                      Square roots
    0 1 1.41421 1.73205 2 2.23607 2.44949

The bond conjunction`&` can be used to bind an argument to a dyad in order to produce a corresponding defined verb. For example:

       square=: ^&2               Square (power and 2)
       square b
    0 1 4 9 16 25 36

       (sqrt=: ^&0.5) b           Square root function
    0 1 1.41421 1.73205 2 2.23607 2.44949

A left argument can be similarly bound:

       Log=: 10&^.                Base-10 logarithm
       Log 2 4 6 8 10 100 1000
    0.30103 0.60206 0.778151 0.90309 1 2 3

Such defined verbs can of course be used in forks. For example:

       in29=: 2&< *. <&9          Interval test
       in29 0 1 2 5 8 13 21
    0 0 0 1 1 0 0

       IN29=: in29 # ]            Interval selection
       IN29 0 1 2 5 8 13 21
    5 8

       LOE=: <+.=
       5 LOE 3 4 5 6 7
    0 0 1 1 1

       integertest=: <. = ]       The monad <. is floor
       integertest 0 0.5 1 1.5 2 2.5 3
    1 0 1 0 1 0 1

       int=: integertest
       int (i.13)%3
    1 0 0 1 0 0 1 0 0 1 0 0 1

Exercises

7.1 | The verb`#` is used dyadically in the program`IN29` .`` Enter expressions such as`(j=: 3 0 4 0 1) # i.5` to determine the behaviour of`#`,`` and state the result of`#j#i.5` .`` (Also try`1j1#i.5` .) Answer:`+/j`
7.2 | Cover the answers on the right and apply the following programs to lists to determine (and state in English) the purpose of each:
       test1=: >&10 *. <&100      Test if in 10 to 100
       int=: ] = <.               Test if integer
       test2=: int *. test1       Test if integer and in 10 to 100
       test3=: int +. test1       Test if integer or in 10 to 100
       sel=: test2 # ]            Select integers in 10 to 100
7.3 | Cover the program definitions on the left of the preceding exercise, and make new programs for the stated effects.
7.4 | Review the use of the fix adverb in Exercises 6.4-5, and experiment with its use on the programs of Exercise 7.2.

>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Dictionary