OSDN Git Service

Correct i combinator.
authorSimon Forman <sforman@hushmail.com>
Sat, 10 Apr 2021 00:13:09 +0000 (17:13 -0700)
committerSimon Forman <sforman@hushmail.com>
Sat, 10 Apr 2021 00:13:09 +0000 (17:13 -0700)
joy/library.py
joy/utils/stack.py

index c5d7429..dc56dc5 100644 (file)
@@ -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
 
 
index 2f5a653..c460384 100644 (file)
@@ -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