tweaks to list tests.
def __repr__(self):
"Pretty print a term. Will retrieve the complete (ground) term."
+
+ if self.fn == '->/2':
+ return '%s -> %s' % self.args
+
fn = '/'.join(self.fn.split('/')[:-1]) # drop arity from name.
if not self.args:
return fn
# try:
# return cmp(self.aslist, other.aslist)
# except AttributeError:
-# return
+# return
class _Nil(Term):
+
def __init__(self):
Term.__init__(self, 'nil/0', ())
self.aggregator = NoAggregator
Nil = _Nil()
-
-
-#class AList(Cons):
-#
-# def __init__(self, head, tail):
-#
-# if not (isinstance(tail, AList) or tail is Nil):
-# raise TypeError('Malformed alist: tail is not an alist')
-#
-# if not (isinstance(head, Cons) and len(head.aslist) == 2):
-# raise TypeError('Malformed alist: head is not a pair.')
-#
-# Cons.__init__(self, head, tail)
-#
-# def __repr__(self):
-# return '[%s]' % (', '.join('%s -> %s' % (_repr(k), _repr(v)) for k,v in self.aslist))
, ("with_key" ,[(4,PFIn AssocNone ) ])
+ , ("->" ,[(5,PFIn AssocNone ) ])
+
, ("<=" ,[(4,PFIn AssocNone ) ])
, ("<" ,[(4,PFIn AssocNone ) ])
, ("=" ,[(4,PFIn AssocNone ) ])
-- lists
, (("nil", 0),(SDQuote,[]))
, (("cons", 2),(SDQuote,[ADEval,ADEval]))
+ , (("->",2),(SDQuote,[ADQuote, ADQuote]))
]
-- | Make the default surface syntax more functional. Here, all functors
-- key
, (("$key" ,1),(SDEval,[ADQuote]))
, (("with_key",2),(SDQuote,[ADEval, ADQuote]))
+ , (("->",2),(SDQuote,[ADQuote, ADQuote]))
]
------------------------------------------------------------------------}}}
--- /dev/null
+% fun with associative lists
+
+> a = [1 -> "a", 2 -> "b", 3 -> "c", 3 -> "d"].
+|
+| :- backchain findall/2.
+| findall(K,[_|Xs]) := findall(K,Xs).
+| findall(K,[(K -> V)|Xs]) := [V|findall(K,Xs)].
+| findall(_,[]) := [].
+|
+| :- backchain get/2.
+| get(K,[_|Xs]) := get(K,Xs).
+| get(K,[(K -> V)|Xs]) := V.
+| get(_,[]) := null.
+|
+| :- backchain set/3.
+| set(K,V,A) = [K -> V|A].
+
+Changes
+=======
+a = [1 -> a, 2 -> b, 3 -> c, 3 -> d].
+
+> query findall(3, a)
+
+findall(3, a) = ["c", "d"].
+
+> query findall(4, a)
+
+findall(4, a) = [].
+
+> query get(3, a)
+
+get(3, a) = "c".
+
+> query get("three", a)
+
+No results.
+
+> query findall(3, set(3, "three", a))
+
+findall(3, set(3, "three", a)) = ["three", "c", "d"].
\ No newline at end of file
d(4) = true.
% quote is important! or else we enumerate everything!
-> foo(A) := true for &f(A) in [1,2,&f("a"),3].
+> foo(A) := true for &bar(A) in [1,2,&bar("a"),3].
|
-| % this one checks if the value of f(A) is in the list, (note: 1 == True, in python).
-| goo(A) := true for f(A) in [1,2,&f("a"),3].
-
+| bar("int") = 1.
+| bar("bool") = true.
+| bar("spaz") = 2.
+|
+| goo(A) := true for bar(A) in [true,2,&bar("a"),3].
Changes
=======
+bar("bool") = true.
+bar("int") = 1.
+bar("spaz") = 2.
foo("a") = true.
-goo(1) = true.
-goo([1, 2, 3, [2, 1], f(1)]) = true.
-goo([]) = true.
+goo("bool") = true.
+goo("int") = true. % TODO: this should't appear in the results (XREF:bool)
+goo("spaz") = true.
% unfortunately 1 == true and 0 == false in python so the following is true
Changes
=======
-testbool = true.
+testbool = true. % TODO: XREF:bool
% fun with set= at bag=
| thingsbag bag= 1.
| thingsbag bag= 1.
| thingsbag bag= 2.
+| thingsbag bag= true. % XREF:bool
|
| thingset set= "three".
| thingset set= 1.
| thingset set= 1.
+| thingset set= true. % XREF:bool should appear separately in set,
| thingset set= 2.
Changes
=======
-thingsbag = [1, 1, 2, "three"].
+thingsbag = [1, 1, 1, 2, "three"].
thingset = [1, 2, "three"].
-