-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprelude.pnc
97 lines (78 loc) · 1.37 KB
/
prelude.pnc
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# This is the pnc prelude
,e 2.71828182845904523536028747135266250 def
,pi 3.14159265358979323846264338327950288 def
,sqrt2 1.41421356237309504880168872420969808 def
,+ ,add alias
,- ,sub alias
,. ,mul alias
,/ ,div alias
,% ,mod alias
,s ,swap alias
,d ,dup alias
,p ,print alias
,– ,stdin alias
,× ,mul alias
,· ,mul alias
,@ ,map alias
,^ ,pow alias
,peek { dup print } def
,pp ,peek alias
,S { s def } def
,++ { 1 + } def
,-- { 1 - } def
,sum { 0 { + } fold } def
,product { 1 { . } fold } def
,/+ ,sum alias
,/. ,product alias
,1/ { 1 swap div } def
,log10 { 10 log } def
,log2 { 2 log } def
,^2 { 2 pow } def
,abs { dup sign . } def
,sign { 0 cmp } def
,eq { cmp abs 1 swap - } def
,gt { cmp 0 max } def
,ge { -- cmp 0 max } def
,lt { swap cmp 0 max } def
,le { ++ swap cmp 0 max } def
# Delta percent
,d% { over - s / } def
,avg {
dup
len
swap
sum
swap
div
} def
,fib {
0 swap
1 swap
{ dup roll3 + } swap
repeat
pop
} def
,range {
[
arg # from
arg # to
swap over -
d 0 ge
{
{ dup ++ } swap repeat
}
{ pop pop }
if
]
} def
,seq ,range alias
,.. ,range alias
,upto { 1 swap range } def
,! { seq /. } def
,choose { over over - ! s ! . s ! s / } def
,vmax {
{ max } fold1
} def
,vmin {
{ min } fold1
} def