def cons(x, s): from clojure.lang.cons import Cons from clojure.lang.persistentlist import EMPTY as EMPTY_LIST if isinstance(s, ISeq): return Cons(x, s) if s is None: return EMPTY_LIST.cons(x) return Cons(x, seq(s))
def setUp(self): # if this raises no exceptions, the others will validate creation self.head = "head" self.t1 = pl.creator(uobj) self.t2 = pl.creator(0, uobj) self.t3 = pl.creator(0, 1, uobj) self.c1 = Cons(self.head, None) self.c2 = Cons(self.head, self.t1) # e.g. ("head" 0 uobj) self.c3 = Cons(self.head, self.t2) self.c4 = Cons(self.head, self.t3) # just checking printed structure self.printS = Cons(pl.creator(1, 2), pl.creator(pl.creator(3, 4)))
def cons(self, other): """Return a Cons. other -- any object The Cons will have object as the head, and this sequence as the tail.""" from clojure.lang.cons import Cons return Cons(other, self)
def seq(self): s = self.root.nodeSeq() if self.root is not None else None return Cons(MapEntry(None, self.noneValue), s) if self.hasNull else s