1
1
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:
Joel Martin 2015-12-30 10:34:53 -07:00
commit 61fb553d02
9 changed files with 16 additions and 8 deletions

View File

@ -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"),

View File

@ -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"),

View File

@ -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"),

View File

@ -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"),

View File

@ -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"],

View File

@ -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"],

View File

@ -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"],

View File

@ -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"],

View File

@ -49,6 +49,10 @@
;=>(1 2 (3 4))
`(1 2 (3 4))
;=>(1 2 (3 4))
(quasiquote (nil))
;=>(nil)
`(nil)
;=>(nil)
;; Testing unquote