Commits

Carl Friedrich Bolz committed eb955d5

gah, fix formatting of lists

Comments (0)

Files changed (2)

prolog/builtin/formatting.py

             result = ["["]
             while helper.is_term(term) and isinstance(term, Callable) and term.signature().eq(conssig):
                 first = term.argument_at(0)
-                second = term.argument_at(1)
+                second = term.argument_at(1).dereference(None)
                 result.append(self.format(first))
                 result.append(", ")
                 term = second

prolog/builtin/test/test_formatting.py

 from prolog.builtin import formatting
 from prolog.interpreter.parsing import parse_query_term
 from prolog.interpreter.continuation import Engine
+from prolog.interpreter.term import Callable, BindingVar
 
 def test_list():
     f = formatting.TermFormatter(Engine(), quoted=False, ignore_ops=False)
     t = parse_query_term("'.'(a, b, c).")
     assert f.format(t) == ".(a, b, c)"
 
+    X = BindingVar()
+    a = Callable.build('a')
+    t = Callable.build(".", [a, X])
+    X.binding = Callable.build(".", [a, Callable.build("[]")])
+    assert f.format(t) == "[a, a]"
+
+
+
 def test_op_formatting():
     f = formatting.TermFormatter(Engine(), quoted=False, ignore_ops=False)
     t = parse_query_term("'+'(1, 2).")