JPhrases/Gerunds

From J Wiki
Jump to: navigation, search

2H. Gerunds

The phrases included here illustrate the following uses of gerunds:

  • Insertion
  • Case statement
  • Recursion
  • Power
m0=: horner=: +`*/ m0 a,x,b,x,c is (a,b,c)p.x
m1=: grid=: +`(*i.)/ grid b,s,n From b in n s-steps
m2=: case1=: _1:`%:`*:@.*"0 Sqr, _1, or sq root if neg, zero, or pos
d3=: sort=: /:~@]`(\:~@])@.[ Sort up or down for left 0 or 1
v4=: cases=: case1 : sort Ambivalent function
a5=: sel=: 1 : '] #~ ] x. {.' Selection for Quicksort
m6=: qs=: ] ` ($:@(<sel), =sel, $:@(>sel)) @. (1:<#) Quicksort defined recursively
m7=: (0&,+,&0)^:([`1:) Binomial coefficients (gerundial power)