(if) without else case is now supported.
This commit is contained in:
parent
5c6e78eab5
commit
ea0d4c3b4a
@ -53,7 +53,7 @@ function Lisp (input, lib) {
|
|||||||
if (interpret(input[1], context)) {
|
if (interpret(input[1], context)) {
|
||||||
return interpret(input[2], context)
|
return interpret(input[2], context)
|
||||||
}
|
}
|
||||||
return interpret(input[3], context)
|
return input[3] ? interpret(input[3], context) : []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ function Lisp (input, lib) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const interpret = function (input, context) {
|
const interpret = function (input, context) {
|
||||||
if (!input) { return null }
|
if (!input) { console.warn('error', context.scope); return null }
|
||||||
|
|
||||||
if (context === undefined) {
|
if (context === undefined) {
|
||||||
return interpret(input, new Context(lib))
|
return interpret(input, new Context(lib))
|
||||||
|
@ -21,13 +21,12 @@
|
|||||||
(test "gt" (gt 3 4) false)
|
(test "gt" (gt 3 4) false)
|
||||||
|
|
||||||
(test "and - true" (and 1 2 true 4) 4)
|
(test "and - true" (and 1 2 true 4) 4)
|
||||||
|
|
||||||
(test "and - false" (and 1 false 2) false)
|
(test "and - false" (and 1 false 2) false)
|
||||||
|
|
||||||
(test "or - true" (or false false 2 false) 2)
|
(test "or - true" (or false false 2 false) 2)
|
||||||
|
|
||||||
(test "if - branch 1" (if (gt 3 2) ("branch 1") ("branch 2")) "branch 1")
|
(test "if - branch 1" (if (gt 3 2) ("branch 1") ("branch 2")) "branch 1")
|
||||||
(test "if - branch 2" (if (lt 3 2) ("branch 1") ("branch 2")) "branch 2")
|
(test "if - branch 2" (if (lt 3 2) ("branch 1") ("branch 2")) "branch 2")
|
||||||
|
(test "if - no else" (if (lt 3 2) ("branch 1")) ())
|
||||||
|
|
||||||
; Arrays
|
; Arrays
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user