aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-27 23:49:11 -0500
committerJoel Martin <github@martintribe.org>2015-01-06 21:59:01 -0600
commitb554fd4ed035396886c673778d60659085d8b286 (patch)
tree09c309842066a6122563a725fd801c16732724e9
parent77b2da6cf337bbd85914619bfbccba69b6621a04 (diff)
downloadmal-b554fd4ed035396886c673778d60659085d8b286.tar.gz
mal-b554fd4ed035396886c673778d60659085d8b286.zip
rust: fix quote/quasiquote of vectors.
-rw-r--r--rust/src/step7_quote.rs6
-rw-r--r--rust/src/step8_macros.rs6
-rw-r--r--rust/src/step9_try.rs6
-rw-r--r--rust/src/stepA_interop.rs6
-rw-r--r--tests/step7_quote.mal25
5 files changed, 31 insertions, 18 deletions
diff --git a/rust/src/step7_quote.rs b/rust/src/step7_quote.rs
index bdfdf24..a46f548 100644
--- a/rust/src/step7_quote.rs
+++ b/rust/src/step7_quote.rs
@@ -26,7 +26,7 @@ fn read(str: String) -> MalRet {
// eval
fn is_pair(x: MalVal) -> bool {
match *x {
- List(ref lst,_) => lst.len() > 0,
+ List(ref lst,_) | Vector(ref lst,_) => lst.len() > 0,
_ => false,
}
}
@@ -37,7 +37,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
match *ast.clone() {
- List(ref args,_) => {
+ List(ref args,_) | Vector(ref args,_) => {
let ref a0 = args[0];
match **a0 {
Sym(ref s) => {
@@ -50,7 +50,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
if is_pair(a0.clone()) {
match **a0 {
- List(ref a0args,_) => {
+ List(ref a0args,_) | Vector(ref a0args,_) => {
let a00 = a0args[0].clone();
match *a00 {
Sym(ref s) => {
diff --git a/rust/src/step8_macros.rs b/rust/src/step8_macros.rs
index 3e5f8a7..fbbaf35 100644
--- a/rust/src/step8_macros.rs
+++ b/rust/src/step8_macros.rs
@@ -26,7 +26,7 @@ fn read(str: String) -> MalRet {
// eval
fn is_pair(x: MalVal) -> bool {
match *x {
- List(ref lst,_) => lst.len() > 0,
+ List(ref lst,_) | Vector(ref lst,_) => lst.len() > 0,
_ => false,
}
}
@@ -37,7 +37,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
match *ast.clone() {
- List(ref args,_) => {
+ List(ref args,_) | Vector(ref args,_) => {
let ref a0 = args[0];
match **a0 {
Sym(ref s) => {
@@ -50,7 +50,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
if is_pair(a0.clone()) {
match **a0 {
- List(ref a0args,_) => {
+ List(ref a0args,_) | Vector(ref a0args,_) => {
let a00 = a0args[0].clone();
match *a00 {
Sym(ref s) => {
diff --git a/rust/src/step9_try.rs b/rust/src/step9_try.rs
index c36abcb..4449661 100644
--- a/rust/src/step9_try.rs
+++ b/rust/src/step9_try.rs
@@ -26,7 +26,7 @@ fn read(str: String) -> MalRet {
// eval
fn is_pair(x: MalVal) -> bool {
match *x {
- List(ref lst,_) => lst.len() > 0,
+ List(ref lst,_) | Vector(ref lst,_) => lst.len() > 0,
_ => false,
}
}
@@ -37,7 +37,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
match *ast.clone() {
- List(ref args,_) => {
+ List(ref args,_) | Vector(ref args,_) => {
let ref a0 = args[0];
match **a0 {
Sym(ref s) => {
@@ -50,7 +50,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
if is_pair(a0.clone()) {
match **a0 {
- List(ref a0args,_) => {
+ List(ref a0args,_) | Vector(ref a0args,_) => {
let a00 = a0args[0].clone();
match *a00 {
Sym(ref s) => {
diff --git a/rust/src/stepA_interop.rs b/rust/src/stepA_interop.rs
index c36abcb..4449661 100644
--- a/rust/src/stepA_interop.rs
+++ b/rust/src/stepA_interop.rs
@@ -26,7 +26,7 @@ fn read(str: String) -> MalRet {
// eval
fn is_pair(x: MalVal) -> bool {
match *x {
- List(ref lst,_) => lst.len() > 0,
+ List(ref lst,_) | Vector(ref lst,_) => lst.len() > 0,
_ => false,
}
}
@@ -37,7 +37,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
match *ast.clone() {
- List(ref args,_) => {
+ List(ref args,_) | Vector(ref args,_) => {
let ref a0 = args[0];
match **a0 {
Sym(ref s) => {
@@ -50,7 +50,7 @@ fn quasiquote(ast: MalVal) -> MalVal {
}
if is_pair(a0.clone()) {
match **a0 {
- List(ref a0args,_) => {
+ List(ref a0args,_) | Vector(ref a0args,_) => {
let a00 = a0args[0].clone();
match *a00 {
Sym(ref s) => {
diff --git a/tests/step7_quote.mal b/tests/step7_quote.mal
index 38dac01..979b4a9 100644
--- a/tests/step7_quote.mal
+++ b/tests/step7_quote.mal
@@ -47,9 +47,6 @@
;=>(1 b 3)
`(1 ~b 3)
;=>(1 (1 "b" "d") 3)
-;;; TODO: fix this
-;;;`[1 ~b 3]
-;;;;=>[1 (1 "b" "d") 3]
;; Testing splice-unquote
@@ -59,9 +56,6 @@
;=>(1 c 3)
`(1 ~@c 3)
;=>(1 1 "b" "d" 3)
-;;; TODO: fix this
-;;;`[1 ~@c 3]
-;;;;=>[1 1 "b" "d" 3]
;; Testing symbol equality
@@ -78,3 +72,22 @@
;;; TODO: needs expect line length fix
;;;((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
;;;=>((fn* [q] (quasiquote ((unquote q) (quote (unquote q))))) (quote (fn* [q] (quasiquote ((unquote q) (quote (unquote q)))))))
+
+;;
+;; -------- Optional Functionality --------
+
+;; Testing unquote with vectors
+(def! a 8)
+;=>8
+`[1 a 3]
+;=>(1 a 3)
+;;; TODO: fix this
+;;;;=>[1 a 3]
+
+;; Testing splice-unquote with vectors
+(def! c '(1 "b" "d"))
+;=>(1 "b" "d")
+`[1 ~@c 3]
+;=>(1 1 "b" "d" 3)
+;;; TODO: fix this
+;;;;=>[1 1 "b" "d" 3]