-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathUtil.fs
46 lines (43 loc) · 1.38 KB
/
Util.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
######################################################
##
## Util:
##
## A lexicon of common utility words.
##
## John Earnest
##
######################################################
: 0= if false else true then ;
: 0! if true else false then ;
: on true swap ! ;
: off false swap ! ;
: 2inc 1 + swap 1 + swap ; ( a b -- a+1 b+1 )
: 2dec 1 - swap 1 - swap ; ( a b -- a-1 b-1 )
: inc@ dup @ 1 + swap ! ;
: dec@ dup @ 1 - swap ! ;
: toggle dup @ not swap ! ;
: neg@ dup @ -1 * swap ! ;
: swap@ 2dup @ >r @ swap ! r> swap ! ;
: inc-r r> r> 1 + >r >r ;
: dec-r r> r> 1 - >r >r ;
: +@ swap over @ swap + swap ! ; ( val addr -- )
: -@ swap over @ swap - swap ! ;
: random RN @ swap mod ;
: brownian RN @ 3 mod 1 - ;
: abs dup 0 < if -1 * then ;
: later r> r> swap >r >r ;
: exitif if rdrop exit then ;
: tuck swap over ;
: ?dup dup if dup then ;
: within over >= >r <= r> and ; ( min v max -- flag )
: sgn ( n -- -1 | 0 | 1 )
dup 0 > 1 and
swap 0 < 1 and -
;
: indexof (value array -- address)
loop
2dup @ =
if swap drop exit then
1 +
again
;