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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
| # Garepinoh
This describes Garepinoh as of `Mon Jan 20 23:42:59 CET 2014`. Try
`garepinoh ,,help` or so to get some current information. Or just read
the source code. :P
## About
**Garepinoh** is a reverse prefix notation calculator written in
Haskell. Within "Garepinoh", *G* stands for *GPL* (which formerly was
its license), *r*, *p* and *n* stand for *reverse prefix notation* and
*h* for *Haskell*.
Garepinoh is not actively developed anymore. The (main-(?))author,
*Mekeor Melire*, moved on to work on a similar project, called
[*tyred*](http://hub.darcs.net/mekeor/tyred) (which might be uploaded
soon).
## Usage
### Using the program `garepinoh`
#### Interpretation
To "interprete" a source file "source.garepinoh", just type (in your
shell):
$ cat source.garepinoh | garepinoh
#### REPL
To invoke read-eval-print loop handling numeric values, just execute
(in your shell):
$ garepinoh
To invoke read-eval-print loop handling numeric values, just execute
(in your shell):
$ garepiboh
(That is, change the *n* (meaning *numeric*) to *b* (meaning
*boolean*) in `garepinoh`.)
#### Loading
To load a source file `source.garepinoh` into Garepinoh, write (in
your shell):
$ cat source.garepinoh - | garepinoh
### Syntax
#### Evaluation
* If the first word of the line is `,,`, the rest of the line is a
comment. Else:
* Else: If the first word of the line is `,` and some `<f>` is the
next word and there are no other words, this postulates a new
function `<f>`.
* Else: If the first word of the line is `,,<c>`, this executes the
command `<c>`.
* Else: If the first word of the line is `,` and the next word is
`<f>`, this defines the function `<f>` and the rest of the line is
its definition.
* Else: This is a sequence of words which are evaluated iteratively:
* If a word can be read as a value, it's pushed onto the
stack.
* Else: If a word can be read as a function, this function is
applied onto the stack.
Application uses reverse prefix notation: If you would
write `f x y z` in prefix notation (like in Haskell or in Lisp),
you write `z y x f` in Garepinoh.
Particulary, if you would write `(-) 1 2` in Haskell, you write
`2 1 -` in Garepinoh.
* Else: If a word begins with a `,`, and the rest of the word can
be read as a function, this function is pushed onto the
stack.
* Else: This word is invalid.
#### Commands
* quit, q, exit, x
* help, h
* func, f, functions
* cmnd, c, commands
#### Preludes
##### Numeric Prelude
* swap, swp, s
* drop, drp, d
* flip
* emptylist, el, []
* cons, #, :
* dup, duplicate
* map
* curry, ,, c
* apply, $, a
* id, identity
* geneq, generalequality
* appendlist, unlist
* ., functioncomposition, comp, ∘
* addition, add, plus, +
* subtraction, -, minus, take, subtract
* multiplication, times, *, ·, ×
* division, div, /, %, \, ÷
* exponentiation, pow, power, ^, **
* logarithm, log, logbase, ?
* pi, π
* e, euler
* i
* sqrt
* bool, tei, thenelseif
##### Boolean Prelude
* swap, swp, s
* drop, drp, d
* flip
* emptylist, el, []
* cons, #, :
* dup, duplicate
* map
* curry, ,, c
* apply, $, a
* id, identity
* geneq, generalequality
* appendlist, unlist
* ., functioncomposition, comp, ∘
* conjunction, and, &, &&, ∧
* disjunction, or, |, ||, ∨
* not, -, ~, ¬
* nand
* bool, tei, thenelseif
* true, t, 1
* false, f, 0
## Examples
### Factorial
Definition of factorial for natural numbers greater than or equal to
zero:
, ! dup 1 ,- flip c c dup ,drop ,! ,* . bool a
### Fibonacci
A nice derivation of a function which, given a number `n`, returns the
n-th Fibonacci-number:
,, f dup ,zero ,notzero bool a
, zero drop 0
, notzero
, f dup ,zero ,notzero bool a
,, notzero dup subtractone ,one ,notone bool a
, subtractone 1 ,- flip c c
, one drop 1
, notone
, notzero dup subtractone ,one ,notone bool a
, notone subtractone dup subtractone f swp f +
[] 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : ,f map unlist
,, output: [55.0,34.0,21.0,13.0,8.0,5.0,3.0,2.0,1.0,1.0]
Of course, one would write it different when one already knew from the
beginning on how to define it. Maybe like this:
, one drop 1
, zero drop 0
, subtractone 1 ,- flip c c
, f
, notone subtractone dup subtractone f swp f +
, notzero dup subtractone ,one ,notone bool a
, f dup ,zero ,notzero bool a
|