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