From a56edfe0c4ff207aaf2b620c2e405a088b2b444f Mon Sep 17 00:00:00 2001 From: Nischal Shrestha Date: Sun, 8 Sep 2019 02:37:56 -0400 Subject: [PATCH] Cast map return values to lists For Python 3.x, map() returns a map object which needs to be cast to a list for some of the return values in the expand and let methods. Otherwise, some tests will fail. --- py/lispy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py/lispy.py b/py/lispy.py index 1d8af76..132ea6f 100644 --- a/py/lispy.py +++ b/py/lispy.py @@ -230,7 +230,7 @@ def expand(x, toplevel=False): elif x[0] is _if: if len(x)==3: x = x + [None] # (if t c) => (if t c None) require(x, len(x)==4) - return map(expand, x) + return list(map(expand, x)) elif x[0] is _set: require(x, len(x)==3); var = x[1] # (set! non-var exp) => Error @@ -269,7 +269,7 @@ def expand(x, toplevel=False): elif isa(x[0], Symbol) and x[0] in macro_table: return expand(macro_table[x[0]](*x[1:]), toplevel) # (m arg...) else: # => macroexpand if m isa macro - return map(expand, x) # (f arg...) => expand each + return list(map(expand, x)) # (f arg...) => expand each def require(x, predicate, msg="wrong length"): "Signal a syntax error if predicate is false." @@ -299,7 +299,7 @@ def let(*args): require(x, all(isa(b, list) and len(b)==2 and isa(b[0], Symbol) for b in bindings), "illegal binding list") vars, vals = zip(*bindings) - return [[_lambda, list(vars)]+map(expand, body)] + map(expand, vals) + return [[_lambda, list(vars)]+list(map(expand, body))] + list(map(expand, vals)) macro_table = {_let:let} ## More macros can go here