From 8e4de1ed14edf0c980643852d0663afa214e1202 Mon Sep 17 00:00:00 2001 From: Dov Murik Date: Sun, 21 Jul 2019 10:53:41 +0300 Subject: [PATCH 1/4] io: Fix list and vector equality Previously we relied on Io's list equality, but this doesn't hold for non-primitive elements in the list, so (= [:abc] [:abc]) returned false. --- io/MalTypes.io | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/io/MalTypes.io b/io/MalTypes.io index 975696339c..5695435d32 100644 --- a/io/MalTypes.io +++ b/io/MalTypes.io @@ -30,6 +30,14 @@ MalKeyword := Object clone do ( MalSequential := Object clone do( isSequential := method(true) + equalSequence := method(other, + if((other ?isSequential) not, return false) + if(self size != other size, return false) + unequalElement := self detect(i, valA, + (valA == (other at(i))) not + ) + if(unequalElement, false, true) + ) ) MalList := List clone appendProto(MalSequential) appendProto(MalMeta) do ( @@ -39,6 +47,7 @@ MalList := List clone appendProto(MalSequential) appendProto(MalMeta) do ( ) rest := method(MalList with(resend)) slice := method(MalList with(resend)) + == := method(other, equalSequence(other)) ) MalVector := List clone appendProto(MalSequential) appendProto(MalMeta) do ( @@ -48,6 +57,7 @@ MalVector := List clone appendProto(MalSequential) appendProto(MalMeta) do ( ) rest := method(MalList with(resend)) slice := method(MalList with(resend)) + == := method(other, equalSequence(other)) ) MalMap := Map clone appendProto(MalMeta) do ( From fd308353abf9e7a173207ac5eaebeaa024ae78bd Mon Sep 17 00:00:00 2001 From: Dov Murik Date: Sun, 21 Jul 2019 10:53:54 +0300 Subject: [PATCH 2/4] io: keyword and symbol accept a keyword/symbol argument --- io/MalTypes.io | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/MalTypes.io b/io/MalTypes.io index 5695435d32..cd554ed23f 100644 --- a/io/MalTypes.io +++ b/io/MalTypes.io @@ -16,14 +16,14 @@ MalMeta := Object clone do( MalSymbol := Object clone appendProto(MalMeta) do ( val ::= nil - with := method(str, self clone setVal(str)) + with := method(str, self clone setVal(if(str ?val, str val, str))) malPrint := method(readable, val) == := method(other, (self type == other type) and (val == other val)) ) MalKeyword := Object clone do ( val ::= nil - with := method(str, self clone setVal(str)) + with := method(str, self clone setVal(if(str ?val, str val, str))) malPrint := method(readable, ":" .. val) == := method(other, (self type == other type) and (val == other val)) ) From bc396a8b326f0eca2a32d818ba7b739987c05959 Mon Sep 17 00:00:00 2001 From: Dov Murik Date: Sun, 21 Jul 2019 10:54:00 +0300 Subject: [PATCH 3/4] io: Don't mutate existing function when defining a macro --- io/step8_macros.io | 2 +- io/step9_try.io | 2 +- io/stepA_mal.io | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/io/step8_macros.io b/io/step8_macros.io index 21acdc9f70..5f90678db0 100644 --- a/io/step8_macros.io +++ b/io/step8_macros.io @@ -88,7 +88,7 @@ EVAL := method(ast, env, ast = quasiquote(ast at(1)) continue, // TCO "defmacro!", - return(env set(ast at(1), EVAL(ast at(2), env) setIsMacro(true))), + return(env set(ast at(1), EVAL(ast at(2), env) clone setIsMacro(true))), "macroexpand", return(macroexpand(ast at(1), env)) ) diff --git a/io/step9_try.io b/io/step9_try.io index c547e2182e..ed286bc226 100644 --- a/io/step9_try.io +++ b/io/step9_try.io @@ -88,7 +88,7 @@ EVAL := method(ast, env, ast = quasiquote(ast at(1)) continue, // TCO "defmacro!", - return(env set(ast at(1), EVAL(ast at(2), env) setIsMacro(true))), + return(env set(ast at(1), EVAL(ast at(2), env) clone setIsMacro(true))), "macroexpand", return(macroexpand(ast at(1), env)), "try*", diff --git a/io/stepA_mal.io b/io/stepA_mal.io index 55e8911d1f..c3ca0d80e7 100644 --- a/io/stepA_mal.io +++ b/io/stepA_mal.io @@ -88,7 +88,7 @@ EVAL := method(ast, env, ast = quasiquote(ast at(1)) continue, // TCO "defmacro!", - return(env set(ast at(1), EVAL(ast at(2), env) setIsMacro(true))), + return(env set(ast at(1), EVAL(ast at(2), env) clone setIsMacro(true))), "macroexpand", return(macroexpand(ast at(1), env)), "try*", From 0862f64d643b68a7a5afc96e6a16e1857d23181c Mon Sep 17 00:00:00 2001 From: Dov Murik Date: Sun, 21 Jul 2019 10:54:05 +0300 Subject: [PATCH 4/4] io: Atoms can have meta --- io/MalTypes.io | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/MalTypes.io b/io/MalTypes.io index cd554ed23f..afe0a7509d 100644 --- a/io/MalTypes.io +++ b/io/MalTypes.io @@ -119,7 +119,7 @@ MalFunc := Object clone appendProto(MalMeta) do ( call := method(args, blk call(args)) ) -MalAtom := Object clone do ( +MalAtom := Object clone appendProto(MalMeta) do ( val ::= nil with := method(str, self clone setVal(str)) malPrint := method(readable, "(atom " .. (val malPrint(true)) .. ")")