add docstrings
This commit is contained in:
parent
2e4dcf08d8
commit
e8bc9d0ddc
@ -35,18 +35,30 @@ function Lisp (input, lib) {
|
|||||||
return interpret(input[2], letContext)
|
return interpret(input[2], letContext)
|
||||||
},
|
},
|
||||||
def: function (input, context) {
|
def: function (input, context) {
|
||||||
context.scope[input[1].value] = interpret(input[2], context)
|
const identifier = input[1].value
|
||||||
return input[2]
|
const value = (input[2].type === TYPES.string) ? input[3] : input[2]
|
||||||
|
if (input[2].type === TYPES.string) {
|
||||||
|
// docstring
|
||||||
|
console.log(input[2].value)
|
||||||
|
}
|
||||||
|
context.scope[identifier] = interpret(value, context)
|
||||||
|
return value
|
||||||
},
|
},
|
||||||
defn: function(input, context) {
|
defn: function(input, context) {
|
||||||
context.scope[input[1].value] = function() {
|
const identifier = input[1].value
|
||||||
|
const argumentNames = (input[2].type === TYPES.string) ? input[3] : input[2]
|
||||||
|
const functionBody = (input[2].type === TYPES.string) ? input[4] : input[3]
|
||||||
|
if (input[2].type === TYPES.string) {
|
||||||
|
// docstring
|
||||||
|
console.log(input[2].value)
|
||||||
|
}
|
||||||
|
context.scope[identifier] = function() {
|
||||||
const lambdaArguments = arguments
|
const lambdaArguments = arguments
|
||||||
const lambdaScope = input[2].reduce(function (acc, x, i) {
|
const lambdaScope = argumentNames.reduce(function (acc, x, i) {
|
||||||
acc[x.value] = lambdaArguments[i]
|
acc[x.value] = lambdaArguments[i]
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
|
return interpret(functionBody, new Context(lambdaScope, context))
|
||||||
return interpret(input[3], new Context(lambdaScope, context))
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
lambda: function (input, context) {
|
lambda: function (input, context) {
|
||||||
|
@ -48,6 +48,8 @@
|
|||||||
(test "def - func" (addOne 4) 5)
|
(test "def - func" (addOne 4) 5)
|
||||||
(defn addTwo (a) (add 2 a))
|
(defn addTwo (a) (add 2 a))
|
||||||
(test "defn" (addTwo 4) 6)
|
(test "defn" (addTwo 4) 6)
|
||||||
|
(defn mulTwo "multiplies by two" (a) (mul 2 a))
|
||||||
|
(test "docstring" (mulTwo 4) 8)
|
||||||
|
|
||||||
; Generics
|
; Generics
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user