Next: , Previous: , Up: Top  


5 Adverb

Adverbs modify verbs to operative iteritvely over nouns. This previous sentence likley will only make sense once you understand it so let’s jump into an example. Imagine you have a list of 4 lists. Using first you will retrieve the first sub-list. In order to retrieve the first element of each sub-list you’ll have to modify the function first with a modifier each.

Adverb             
f/  over  c/  join
f\  scan  c\  split
f'  each  v'  has  
f': eachp v': bin.
f/: eachr ([n;]f)/: c over
f\: eachl ([n;]f)\: c scan

5.1 scan (over) ⇒ f\x (f/x)

Compute f[x;y] such that f@i=f[f@i-1;x@i]. Scan and over are the same functions except that over only returns the last value.

Given a function of two inputs, output for each x according to...

An example

 (,\)("a";"b";"c")
a
ab
abc
 +\1 20 300
1 21 321
 {y+10*x}\1 20 300
1 30 600
 {y+10*x}/1 20 300
600

5.2 join ⇒ c/x

Join the list of strings x using character c between each pair.

 "-"/("Some";"random text";"plus";,".")
"Some-random text-plus-."

5.3 split ⇒ c\x

Split the string x using character c to determine the locations.

 " "\"Here is a short sentence."
Here     
is       
a        
short    
sentence.

5.4 each ⇒ f’x

Apply function f to each value in list x.

 *((1 2 3);4;(5 6);7)   / first element of the list
1 2 3
 *'((1 2 3);4;(5 6);7)  / first element of each element
1 4 5 7

5.5 has ⇒ v’x

Determine if vector v has element x. Simliar to in but arguments reversed.

 `a`b`c`a`b'`a
1b

`a`b`c`a`b'`d
0b

5.6 eachp ⇒ f’:[x;y]

Apply f[x;y] using the prior value of y, eg. f[y@n;y@n-1]. The first value, n=0, returns f[y@0;x].

 ,':[`x;(`$"y",'$!5)]
y0 x 
y1 y0
y2 y1
y3 y2
y4 y3

 %':[100;100 101.9 105.1 102.3 106.1] / compute returns
1 1.019 1.031403 0.9733587 1.037146

 100%':100 101.9 105.1 102.3 106.1    / using infix notation
1 1.019 1.031403 0.9733587 1.037146

5.6.1 bin ⇒ x’:y

Given a sorted (increasing) list x, find the greatest index, i, where y>x[i].

 n:exp 0.01*!5;n
1 1.01005 1.020201 1.030455 1.040811
 n':1.025
2

5.7 eachr ⇒ f/:

Apply f[x;y] to each value of y, i.e. the right one.

 (!2)+/:!4
0 1
1 2
2 3
3 4

 +/:[!2;!4]
0 1
1 2
2 3
3 4

5.8 eachl ⇒ f\[x;y]

Apply f[x;y] to each value of x, i.e. the left one.

 (!2)+\:!4
0 1 2 3
1 2 3 4

 +\:[!2;!4]
0 1 2 3
1 2 3 4

5.9 n scan (n over) ⇒ x f\:y (x f/:y)

Compute f with initial value x and over list y. f[i] = f[f[i-1];y[i]] except for the case of f[0]=f[x;y[0]]. n over differs from n scan in that it only returns the last value.

 f:{(0.1*x)+0.9*y}      / ema
 0. f\:1+!3
0.9 1.89 2.889
 f:{(`$,/$x),(`$,/$y)} / join and collapse
 `x f\: `y0`y1`y2
x     y0
xy0   y1
xy0y1 y2
 `x f/: `y0`y1`y2
xy0y1 y2

5.10 c(onverge) scan ⇒ f\:x

Compute f[x], f[f[x]] and continue to call f[previous result] until the output converges to a stationary value or the output produces x.

  {x*x}\:.99  / converge to value
0.99 0.9801 0.9605961 ... 1.323698e-18 1.752177e-36 0.

 l:3 4 2 1 4 99 / until output is x
 l\:0
0 3 1 4

 / the latter example worked out manually
 l 0
3
 l 3
1
 l 1
4
 l 4            / f[4]=4 so will stop
4

5.11 c(onverge) over ⇒ f/:x

Same as converge scan but only return last value.

  {x*x}\:.99
0.

5.12 vs ⇒ x\:y

Convert y (base 10) into base x.

 2\:129
10000001b
 16\:255
15 15

5.13 sv ⇒ x/:y

Convert list y (base x) into base 10.

 2/:10101b
21
 16/:15 0 15
3855

Next: , Previous: , Up: Top