mirror of
https://github.com/kanaka/mal.git
synced 2024-09-21 18:48:12 +03:00
Merge pull request #138 from dubek/js-fix-quasiquote-nil
js: Fix exception in `(nil)
This commit is contained in:
commit
61fb553d02
@ -20,7 +20,7 @@ function is_pair(x) {
|
||||
function quasiquote(ast) {
|
||||
if (!is_pair(ast)) {
|
||||
return [types._symbol("quote"), ast];
|
||||
} else if (ast[0].value === 'unquote') {
|
||||
} else if (types._symbol_Q(ast[0]) && ast[0].value === 'unquote') {
|
||||
return ast[1];
|
||||
} else if (is_pair(ast[0]) && ast[0][0].value === 'splice-unquote') {
|
||||
return [types._symbol("concat"),
|
||||
|
@ -20,7 +20,7 @@ function is_pair(x) {
|
||||
function quasiquote(ast) {
|
||||
if (!is_pair(ast)) {
|
||||
return [types._symbol("quote"), ast];
|
||||
} else if (ast[0].value === 'unquote') {
|
||||
} else if (types._symbol_Q(ast[0]) && ast[0].value === 'unquote') {
|
||||
return ast[1];
|
||||
} else if (is_pair(ast[0]) && ast[0][0].value === 'splice-unquote') {
|
||||
return [types._symbol("concat"),
|
||||
|
@ -20,7 +20,7 @@ function is_pair(x) {
|
||||
function quasiquote(ast) {
|
||||
if (!is_pair(ast)) {
|
||||
return [types._symbol("quote"), ast];
|
||||
} else if (ast[0].value === 'unquote') {
|
||||
} else if (types._symbol_Q(ast[0]) && ast[0].value === 'unquote') {
|
||||
return ast[1];
|
||||
} else if (is_pair(ast[0]) && ast[0][0].value === 'splice-unquote') {
|
||||
return [types._symbol("concat"),
|
||||
|
@ -21,7 +21,7 @@ function is_pair(x) {
|
||||
function quasiquote(ast) {
|
||||
if (!is_pair(ast)) {
|
||||
return [types._symbol("quote"), ast];
|
||||
} else if (ast[0].value === 'unquote') {
|
||||
} else if (types._symbol_Q(ast[0]) && ast[0].value === 'unquote') {
|
||||
return ast[1];
|
||||
} else if (is_pair(ast[0]) && ast[0][0].value === 'splice-unquote') {
|
||||
return [types._symbol("concat"),
|
||||
|
@ -17,7 +17,8 @@
|
||||
["def", "quasiquote", ["fn", ["ast"],
|
||||
["if", ["not", ["pair?", "ast"]],
|
||||
["list", ["symbol", ["`", "quote"]], "ast"],
|
||||
["if", ["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]],
|
||||
["if", ["and", ["symbol?", ["nth", "ast", 0]],
|
||||
["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]]],
|
||||
["nth", "ast", 1],
|
||||
["if", ["and", ["pair?", ["nth", "ast", 0]],
|
||||
["=", ["`", "splice-unquote"],
|
||||
|
@ -17,7 +17,8 @@
|
||||
["def", "quasiquote", ["fn", ["ast"],
|
||||
["if", ["not", ["pair?", "ast"]],
|
||||
["list", ["symbol", ["`", "quote"]], "ast"],
|
||||
["if", ["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]],
|
||||
["if", ["and", ["symbol?", ["nth", "ast", 0]],
|
||||
["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]]],
|
||||
["nth", "ast", 1],
|
||||
["if", ["and", ["pair?", ["nth", "ast", 0]],
|
||||
["=", ["`", "splice-unquote"],
|
||||
|
@ -17,7 +17,8 @@
|
||||
["def", "quasiquote", ["fn", ["ast"],
|
||||
["if", ["not", ["pair?", "ast"]],
|
||||
["list", ["symbol", ["`", "quote"]], "ast"],
|
||||
["if", ["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]],
|
||||
["if", ["and", ["symbol?", ["nth", "ast", 0]],
|
||||
["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]]],
|
||||
["nth", "ast", 1],
|
||||
["if", ["and", ["pair?", ["nth", "ast", 0]],
|
||||
["=", ["`", "splice-unquote"],
|
||||
|
@ -17,7 +17,8 @@
|
||||
["def", "quasiquote", ["fn", ["ast"],
|
||||
["if", ["not", ["pair?", "ast"]],
|
||||
["list", ["symbol", ["`", "quote"]], "ast"],
|
||||
["if", ["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]],
|
||||
["if", ["and", ["symbol?", ["nth", "ast", 0]],
|
||||
["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]]],
|
||||
["nth", "ast", 1],
|
||||
["if", ["and", ["pair?", ["nth", "ast", 0]],
|
||||
["=", ["`", "splice-unquote"],
|
||||
|
@ -49,6 +49,10 @@
|
||||
;=>(1 2 (3 4))
|
||||
`(1 2 (3 4))
|
||||
;=>(1 2 (3 4))
|
||||
(quasiquote (nil))
|
||||
;=>(nil)
|
||||
`(nil)
|
||||
;=>(nil)
|
||||
|
||||
|
||||
;; Testing unquote
|
||||
|
Loading…
Reference in New Issue
Block a user