Don't bother to return the expression.
We mutate it instead of replacing it with new versions.
This commit is contained in:
parent
4156da3511
commit
16e6c77fa2
|
|
@ -99,10 +99,10 @@ def joy(stack, expression, dictionary):
|
||||||
func = dictionary[term]
|
func = dictionary[term]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise UnknownSymbolError(term) from None
|
raise UnknownSymbolError(term) from None
|
||||||
stack, expr, dictionary = func(stack, expr, dictionary)
|
stack, dictionary = func(stack, expr, dictionary)
|
||||||
else:
|
else:
|
||||||
stack = term, stack
|
stack = term, stack
|
||||||
return stack, expr, dictionary
|
return stack, dictionary
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
@ -487,7 +487,7 @@ def repl(stack=(), dictionary=None):
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
stack, _, dictionary = run(text, stack, dictionary)
|
stack, dictionary = run(text, stack, dictionary)
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
raise SystemExit from e
|
raise SystemExit from e
|
||||||
except:
|
except:
|
||||||
|
|
@ -526,7 +526,7 @@ def interp(stack=(), dictionary=None):
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
stack, _, dictionary = run(text, stack, dictionary)
|
stack, dictionary = run(text, stack, dictionary)
|
||||||
except UnknownSymbolError as sym:
|
except UnknownSymbolError as sym:
|
||||||
print('Unknown:', sym)
|
print('Unknown:', sym)
|
||||||
except (
|
except (
|
||||||
|
|
@ -584,13 +584,13 @@ def SimpleFunctionWrapper(f):
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def SimpleFunctionWrapper_inner(stack, expr, dictionary):
|
def SimpleFunctionWrapper_inner(stack, expr, dictionary):
|
||||||
return f(stack), expr, dictionary
|
return f(stack), dictionary
|
||||||
|
|
||||||
return SimpleFunctionWrapper_inner
|
return SimpleFunctionWrapper_inner
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
def words(stack, expression, dictionary):
|
def words(stack, _expression, dictionary):
|
||||||
'''
|
'''
|
||||||
Put a list of all the words in alphabetical order onto the stack.
|
Put a list of all the words in alphabetical order onto the stack.
|
||||||
'''
|
'''
|
||||||
|
|
@ -599,7 +599,7 @@ def words(stack, expression, dictionary):
|
||||||
if name.startswith('_'):
|
if name.startswith('_'):
|
||||||
continue
|
continue
|
||||||
w = (Symbol(name), ()), w
|
w = (Symbol(name), ()), w
|
||||||
return (w, stack), expression, dictionary
|
return (w, stack), dictionary
|
||||||
|
|
||||||
|
|
||||||
HELP_TEMPLATE = '''\
|
HELP_TEMPLATE = '''\
|
||||||
|
|
@ -613,14 +613,14 @@ HELP_TEMPLATE = '''\
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
def help_(stack, expression, dictionary):
|
def help_(stack, _expression, dictionary):
|
||||||
'''
|
'''
|
||||||
Accepts a quoted symbol on the top of the stack and prints its docs.
|
Accepts a quoted symbol on the top of the stack and prints its docs.
|
||||||
'''
|
'''
|
||||||
((symbol, _), stack) = stack
|
((symbol, _), stack) = stack
|
||||||
word = dictionary[symbol]
|
word = dictionary[symbol]
|
||||||
print(HELP_TEMPLATE % (symbol, getdoc(word), symbol))
|
print(HELP_TEMPLATE % (symbol, getdoc(word), symbol))
|
||||||
return stack, expression, dictionary
|
return stack, dictionary
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
@ -658,7 +658,7 @@ def branch(stack, expr, dictionary):
|
||||||
isnt_stack(else_)
|
isnt_stack(else_)
|
||||||
isnt_stack(then)
|
isnt_stack(then)
|
||||||
expr.prepend(then if flag else else_)
|
expr.prepend(then if flag else else_)
|
||||||
return stack, expr, dictionary
|
return stack, dictionary
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
|
@ -678,7 +678,7 @@ def dip(stack, expr, dictionary):
|
||||||
isnt_stack(quote)
|
isnt_stack(quote)
|
||||||
expr.prepend((x, ()))
|
expr.prepend((x, ()))
|
||||||
expr.prepend(quote)
|
expr.prepend(quote)
|
||||||
return stack, expr, dictionary
|
return stack, dictionary
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
|
@ -696,7 +696,7 @@ def i(stack, expr, dictionary):
|
||||||
quote, stack = get_n_items(1, stack)
|
quote, stack = get_n_items(1, stack)
|
||||||
isnt_stack(quote)
|
isnt_stack(quote)
|
||||||
expr.prepend(quote)
|
expr.prepend(quote)
|
||||||
return stack, expr, dictionary
|
return stack, dictionary
|
||||||
|
|
||||||
|
|
||||||
LOOP = Symbol('loop')
|
LOOP = Symbol('loop')
|
||||||
|
|
@ -723,7 +723,7 @@ def loop(stack, expr, dictionary):
|
||||||
if flag:
|
if flag:
|
||||||
expr.prepend((quote, (LOOP, ())))
|
expr.prepend((quote, (LOOP, ())))
|
||||||
expr.prepend(quote)
|
expr.prepend(quote)
|
||||||
return stack, expr, dictionary
|
return stack, dictionary
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
|
|
@ -925,7 +925,7 @@ def BinaryLogicWrapper(f):
|
||||||
isnt_bool(a)
|
isnt_bool(a)
|
||||||
isnt_bool(b)
|
isnt_bool(b)
|
||||||
result = f(b, a)
|
result = f(b, a)
|
||||||
return (result, stack), expression, dictionary
|
return (result, stack), dictionary
|
||||||
|
|
||||||
return BinaryLogicWrapper_inner
|
return BinaryLogicWrapper_inner
|
||||||
|
|
||||||
|
|
@ -941,7 +941,7 @@ def BinaryMathWrapper(func):
|
||||||
isnt_int(a)
|
isnt_int(a)
|
||||||
isnt_int(b)
|
isnt_int(b)
|
||||||
result = func(b, a)
|
result = func(b, a)
|
||||||
return (result, stack), expression, dictionary
|
return (result, stack), dictionary
|
||||||
|
|
||||||
return BinaryMathWrapper_inner
|
return BinaryMathWrapper_inner
|
||||||
|
|
||||||
|
|
@ -956,7 +956,7 @@ def UnaryLogicWrapper(f):
|
||||||
a, stack = get_n_items(1, stack)
|
a, stack = get_n_items(1, stack)
|
||||||
isnt_bool(a)
|
isnt_bool(a)
|
||||||
result = f(a)
|
result = f(a)
|
||||||
return (result, stack), expression, dictionary
|
return (result, stack), dictionary
|
||||||
|
|
||||||
return UnaryLogicWrapper_inner
|
return UnaryLogicWrapper_inner
|
||||||
|
|
||||||
|
|
@ -971,7 +971,7 @@ def UnaryMathWrapper(f):
|
||||||
a, stack = get_n_items(1, stack)
|
a, stack = get_n_items(1, stack)
|
||||||
isnt_int(a)
|
isnt_int(a)
|
||||||
result = f(a)
|
result = f(a)
|
||||||
return (result, stack), expression, dictionary
|
return (result, stack), dictionary
|
||||||
|
|
||||||
return UnaryMathWrapper_inner
|
return UnaryMathWrapper_inner
|
||||||
|
|
||||||
|
|
@ -985,7 +985,7 @@ def UnaryWrapper(f):
|
||||||
def UnaryWrapper_inner(stack, expression, dictionary):
|
def UnaryWrapper_inner(stack, expression, dictionary):
|
||||||
a, stack = get_n_items(1, stack)
|
a, stack = get_n_items(1, stack)
|
||||||
result = f(a)
|
result = f(a)
|
||||||
return (result, stack), expression, dictionary
|
return (result, stack), dictionary
|
||||||
|
|
||||||
return UnaryWrapper_inner
|
return UnaryWrapper_inner
|
||||||
|
|
||||||
|
|
@ -1064,7 +1064,7 @@ class Def(object):
|
||||||
|
|
||||||
def __call__(self, stack, expr, dictionary):
|
def __call__(self, stack, expr, dictionary):
|
||||||
expr.prepend(self.body)
|
expr.prepend(self.body)
|
||||||
return stack, expr, dictionary
|
return stack, dictionary
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_definitions(class_, stream, dictionary):
|
def load_definitions(class_, stream, dictionary):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue