A few more primitives

From J Wiki
Jump to navigation Jump to search


<=   =>

The monad i. (integers) result is the list of integers from 0 up to its right argument.

   i. 2
0 1
   i. 4
0 1 2 3 
   i. 6
0 1 2 3 4 5


The dyad $ is called shape.

   5 $ 7	NB. a list of 5 7's
7 7 7 7 7
   8 $ 23	NB. a list of 8 23's
23 23 23 23 23 23 23 23


The monad ? (roll) generates a random number in the range 0 up to 1 less than the argument. An argument of 0 gives a random floating point number greater than or egual to 0 and less than 1. The answers vary depending on how the die rolls.

   ? 10
6
   ? 10
0
   ? 10 10 10 10  NB. 4 numbers in range 0 to 9
3 0 4 6
   ? 5 $ 100	  NB. 5 numbers in range 0 to 99	
58 93 84 52 9
   ? 0 0 0
0.708477 0.553165 0.00766673


The dyad ^ (power) result is the left argument multiplied by itself the number of times given by the right argument.

   3 ^ 2	NB. 3 * 3
9
   2 ^  3	NB. 2 * 2 * 2
8
   2 ^ 4	NB. 2 * 2 * 2 * 2
16
   2 2 2 2 2 2 ^ 0 1 2 3 4 5
1 2 4 8 16 32
   2 ^ 0 1 2 3 4 5
1 2 4 8 16 32
   2 ^ i. 6
1 2 4 8 16 32


The dyad o. (circle) is the letter o inflected with a . (dot), and it provides the circular (trigonometric) functions. In particular, the o. verb with a left argument of 1 gives the sine of the right argument.

   1 o. i.7   
0 0.841471 0.909297 0.14112 _0.756802 _0.958924 _0.279415 


It is hard to tell whether this makes sense or not and it would be better to see this data with a plot.

<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106