es6, js, python, ruby: defmacro! doesn't mutate original function
authorDov Murik <dov.murik@gmail.com>
Tue, 17 Dec 2019 11:16:28 +0000 (13:16 +0200)
committerDov Murik <dov.murik@gmail.com>
Tue, 17 Dec 2019 11:16:28 +0000 (13:16 +0200)
12 files changed:
es6/step8_macros.mjs
es6/step9_try.mjs
es6/stepA_mal.mjs
js/step8_macros.js
js/step9_try.js
js/stepA_mal.js
python/step8_macros.py
python/step9_try.py
python/stepA_mal.py
ruby/step8_macros.rb
ruby/step9_try.rb
ruby/stepA_mal.rb

index 73d9dbb..454949c 100644 (file)
@@ -1,6 +1,6 @@
 import rl from './node_readline.js'
 const readline = rl.readline
-import { _list_Q, _malfunc, _malfunc_Q } from './types'
+import { _clone, _list_Q, _malfunc, _malfunc_Q } from './types'
 import { BlankException, read_str } from './reader'
 import { pr_str } from './printer'
 import { new_env, env_set, env_get } from './env'
@@ -79,7 +79,7 @@ const EVAL = (ast, env) => {
             ast = quasiquote(a1)
             break // continue TCO loop
         case 'defmacro!':
-            let func = EVAL(a2, env)
+            let func = _clone(EVAL(a2, env))
             func.ismacro = true
             return env_set(env, a1, func)
         case 'macroexpand':
index 03eed34..5bc5e25 100644 (file)
@@ -1,6 +1,6 @@
 import rl from './node_readline.js'
 const readline = rl.readline
-import { _list_Q, _malfunc, _malfunc_Q } from './types'
+import { _clone, _list_Q, _malfunc, _malfunc_Q } from './types'
 import { BlankException, read_str } from './reader'
 import { pr_str } from './printer'
 import { new_env, env_set, env_get } from './env'
@@ -79,7 +79,7 @@ const EVAL = (ast, env) => {
             ast = quasiquote(a1)
             break // continue TCO loop
         case 'defmacro!':
-            let func = EVAL(a2, env)
+            let func = _clone(EVAL(a2, env))
             func.ismacro = true
             return env_set(env, a1, func)
         case 'macroexpand':
index 1ee2dc8..68eaa13 100644 (file)
@@ -1,6 +1,6 @@
 import rl from './node_readline.js'
 const readline = rl.readline
-import { _list_Q, _malfunc, _malfunc_Q } from './types'
+import { _clone, _list_Q, _malfunc, _malfunc_Q } from './types'
 import { BlankException, read_str } from './reader'
 import { pr_str } from './printer'
 import { new_env, env_set, env_get } from './env'
@@ -79,7 +79,7 @@ const EVAL = (ast, env) => {
             ast = quasiquote(a1)
             break // continue TCO loop
         case 'defmacro!':
-            let func = EVAL(a2, env)
+            let func = _clone(EVAL(a2, env))
             func.ismacro = true
             return env_set(env, a1, func)
         case 'macroexpand':
index b5b975f..68927e1 100644 (file)
@@ -104,7 +104,7 @@ function _EVAL(ast, env) {
         ast = quasiquote(a1);
         break;
     case 'defmacro!':
-        var func = EVAL(a2, env);
+        var func = types._clone(EVAL(a2, env));
         func._ismacro_ = true;
         return env.set(a1, func);
     case 'macroexpand':
index 08a853e..5ae9c77 100644 (file)
@@ -104,7 +104,7 @@ function _EVAL(ast, env) {
         ast = quasiquote(a1);
         break;
     case 'defmacro!':
-        var func = EVAL(a2, env);
+        var func = types._clone(EVAL(a2, env));
         func._ismacro_ = true;
         return env.set(a1, func);
     case 'macroexpand':
index 4e6e49d..6b7e7f0 100644 (file)
@@ -104,7 +104,7 @@ function _EVAL(ast, env) {
         ast = quasiquote(a1);
         break;
     case 'defmacro!':
-        var func = EVAL(a2, env);
+        var func = types._clone(EVAL(a2, env));
         func._ismacro_ = true;
         return env.set(a1, func);
     case 'macroexpand':
index 7cc9981..3b6f8a6 100644 (file)
@@ -87,7 +87,7 @@ def EVAL(ast, env):
             ast = quasiquote(ast[1]);
             # Continue loop (TCO)
         elif 'defmacro!' == a0:
-            func = EVAL(ast[2], env)
+            func = types._clone(EVAL(ast[2], env))
             func._ismacro_ = True
             return env.set(ast[1], func)
         elif 'macroexpand' == a0:
index bebe459..2d14816 100644 (file)
@@ -87,7 +87,7 @@ def EVAL(ast, env):
             ast = quasiquote(ast[1]);
             # Continue loop (TCO)
         elif 'defmacro!' == a0:
-            func = EVAL(ast[2], env)
+            func = types._clone(EVAL(ast[2], env))
             func._ismacro_ = True
             return env.set(ast[1], func)
         elif 'macroexpand' == a0:
index 8f4752f..dedca29 100644 (file)
@@ -87,7 +87,7 @@ def EVAL(ast, env):
             ast = quasiquote(ast[1]);
             # Continue loop (TCO)
         elif 'defmacro!' == a0:
-            func = EVAL(ast[2], env)
+            func = types._clone(EVAL(ast[2], env))
             func._ismacro_ = True
             return env.set(ast[1], func)
         elif 'macroexpand' == a0:
index 3dcce5c..a9cc51d 100644 (file)
@@ -94,7 +94,7 @@ def EVAL(ast, env)
     when :quasiquote
         ast = quasiquote(a1); # Continue loop (TCO)
     when :defmacro!
-        func = EVAL(a2, env)
+        func = EVAL(a2, env).clone
         func.is_macro = true
         return env.set(a1, func)
     when :macroexpand
index b0aa5c8..0c342a0 100644 (file)
@@ -94,7 +94,7 @@ def EVAL(ast, env)
     when :quasiquote
         ast = quasiquote(a1); # Continue loop (TCO)
     when :defmacro!
-        func = EVAL(a2, env)
+        func = EVAL(a2, env).clone
         func.is_macro = true
         return env.set(a1, func)
     when :macroexpand
index 037cd8c..2f96f37 100644 (file)
@@ -94,7 +94,7 @@ def EVAL(ast, env)
     when :quasiquote
         ast = quasiquote(a1); # Continue loop (TCO)
     when :defmacro!
-        func = EVAL(a2, env)
+        func = EVAL(a2, env).clone
         func.is_macro = true
         return env.set(a1, func)
     when :macroexpand