-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.js
33 lines (32 loc) · 869 Bytes
/
core.js
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
const fs = require('fs')
module.exports = {
help() {
console.log('Welcome to lisp-node - a super tiny LISP interpreter!')
console.log('')
console.log('Here are some examples:')
console.log(' (sum-to 100): calculate sum of [1..100]')
console.log(' (fact 10): calculate factorial 100')
console.log(' (pow 2 10): calculates 2^10')
console.log(' (debug): toggles debugging information')
console.log(' (exit): exit lisp-node REPL')
console.log('')
},
'='(a, b) {
return a === b
},
'+'(...[head, ...tail]) {
return tail.reduce((a, b) => a + b, head)
},
'-'(...[head, ...tail]) {
return tail.reduce((a, b) => a - b, head)
},
'*'(...[head, ...tail]) {
return tail.reduce((a, b) => a * b, head)
},
'/'(...[head, ...tail]) {
return tail.reduce((a, b) => a / b, head)
},
'read-file'(path) {
return fs.readFileSync(path)
},
}