Correct i combinator.
This commit is contained in:
parent
fbdd79a8db
commit
49bcab2e91
|
|
@ -842,7 +842,10 @@ def i(stack, expression, dictionary):
|
|||
Q
|
||||
|
||||
'''
|
||||
quote, stack = stack
|
||||
try:
|
||||
quote, stack = stack
|
||||
except ValueError:
|
||||
raise StackUnderflowError
|
||||
return stack, concat(quote, expression), dictionary
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ printed left-to-right. These functions are written to support :doc:`../pretty`.
|
|||
.. _cons list: https://en.wikipedia.org/wiki/Cons#Lists
|
||||
|
||||
'''
|
||||
from .errors import NotAListError
|
||||
|
||||
|
||||
def list_to_stack(el, stack=()):
|
||||
|
|
@ -164,7 +165,7 @@ def concat(quote, expression):
|
|||
# RuntimeError: maximum recursion depth exceeded
|
||||
# on quotes longer than sys.getrecursionlimit().
|
||||
|
||||
return (quote[0], concat(quote[1], expression)) if quote else expression
|
||||
## return (quote[0], concat(quote[1], expression)) if quote else expression
|
||||
|
||||
# Original implementation.
|
||||
|
||||
|
|
@ -173,13 +174,15 @@ def concat(quote, expression):
|
|||
# In-lining is slightly faster (and won't break the
|
||||
# recursion limit on long quotes.)
|
||||
|
||||
## temp = []
|
||||
## while quote:
|
||||
## item, quote = quote
|
||||
## temp.append(item)
|
||||
## for item in reversed(temp):
|
||||
## expression = item, expression
|
||||
## return expression
|
||||
temp = []
|
||||
while quote:
|
||||
if not isinstance(quote, tuple):
|
||||
raise NotAListError
|
||||
item, quote = quote
|
||||
temp.append(item)
|
||||
for item in reversed(temp):
|
||||
expression = item, expression
|
||||
return expression
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue