def __init__(self, *args): """Symbol initializer. Valid calls: - Symbol(symbol) -- copy, - Symbol([[mapping,] str,], str) -- metadata, namespace, name. """ if len(args) == 1: arg = args[0] if isinstance(arg, Symbol): self._meta, self.ns, self.name = arg._meta, arg.ns, arg.name else: self._meta = None idx = arg.rfind("/") if idx == -1 or arg == "/": self.ns = None self.name = arg else: self.ns = arg[:idx] self.name = arg[idx + 1:] elif len(args) == 2: self._meta = None self.ns, self.name = args elif len(args) == 3: self._meta, self.ns, self.name = args else: raise ArityException()
def reduce(self, *args): """Reduce this list to a single value. args must be one of: * IFn * IFn, object If this list contains one item, return it. Else, apply the given binary function to the first two items in the list. The result of that becomes the first argument of the next application of the function with the third item as the second argument. This continues until this list is exhausted. If the second argument is supplied to reduce, it's treated as the first item in this list. Return the result of this reduction. May raise ArityException.""" if len(args) == 1: ret = self.first() elif len(args) == 2: ret = args[0](args[1], self.first()) else: raise ArityException() fn = args[0] s = self.next() while s is not None: ret = fn(ret, s.first()) s = s.next() return ret
def __init__(self, *args): if len(args) == 0: self._meta = None self.comp = RT.DefaultComparator() self.tree = None self._count = 0 elif len(args) == 1: self._meta = None self.comp = args[0] self.tree = None self._count = 0 elif len(args) == 2: self._meta = args[0] self.comp = args[1] self.tree = None self._count = 0 elif len(args) == 4 and isinstance(args[0], IPersistentMap): self._meta = args[0] self.comp = args[1] self.tree = args[2] self._count = args[2] elif len(args) == 4 and isinstance(args[0], Comparator): self.comp = args[0] self.tree = args[1] self._count = args[2] self._meta = args[3] else: raise ArityException()
def __init__(self, *args): if len(args) == 3: self.array, self.i, self.s = args elif len(args) == 4: self._meta, self.array, self.i, self.s = args else: raise ArityException()
def __call__(self, *args): """Return the single item in args if found in this set, else None. args -- must be one object""" if len(args) != 1: raise ArityException() return self.impl[args[0]]
def __init__(self, *args): if len(args) == 1: self._seq = args[0] elif len(args) == 2: self._meta = args[0] self._seq = args[1] else: raise ArityException()
def find(self, *args): if len(args) == 1: if isinstance(args[0], Symbol): return interned.val()[args[0]]() if isinstance(args[0], str): return Keyword.find(symbol(args[0])) if len(args) == 2: return Keyword.find(symbol(*args)) raise ArityException()
def __init__(self, *args): if len(args) == 2: self._meta = None self._first = args[0] self._more = args[1] elif len(args) == 3: self._meta = args[0] self._first = args[1] self._more = args[2] else: raise ArityException()
def seq(self, *args): if len(args) == 0: if self._count > 0: return createSeq(self.tree, True, self._count) return None elif len(args) == 1: ascending = args[0] if self._count > 0: return createSeq(self.tree, ascending, self._count) return None else: raise ArityException()
def reduce(self, *args): if len(args) == 1: ret = self.first() elif len(args) == 2: ret = args[0](args[1], self.first()) else: raise ArityException() fn = args[0] s = self.next() while s is not None: ret = fn(ret, s.first()) return ret
def __init__(self, *args): if len(args) == 0: self.array = [] self._meta = None elif len(args) == 1: self.array = args[0] self._meta = None elif len(args) == 2: self._meta = args[0] self.array = args[1] else: raise ArityException()
def __init__(self, *args): if len(args) == 2: self.ns = args[0].name if isinstance(args[0], Symbol) else args[0] self.name = args[1] self._meta = None elif len(args) == 3: self._meta = args[0] self.ns = args[1] self.name = args[2] else: raise ArityException() if isinstance(self.ns, types.ModuleType): pass
def validate(self, *args): if len(args) == 1: val = args[0] vf = self.validator elif len(args) == 2: vf = args[0] val = args[1] else: raise ArityException() if vf is not None \ and not RT.booleanCast(vf(val)): raise IllegalStateException("Invalid reference state")
def __init__(self, *args): if len(args) == 4: cnt, shift, root, tail = args _meta = None elif len(args) == 5: _meta, cnt, shift, root, tail = args else: raise ArityException() self._meta = _meta self.cnt = cnt self.shift = shift self.root = root self.tail = tail
def symbol(*args): if len(args) == 1: a = args[0] if isinstance(a, Symbol): return a idx = a.rfind("/") if idx == -1 or a == "/": return Symbol(None, a) else: return Symbol(a[idx:], a[:idx + 1]) elif len(args) == 2: return Symbol(args[0], args[1]) else: raise ArityException()
def createSeq(*args): if len(args) == 1: return createSeq(None, args[0], 0, None) if len(args) != 4: raise ArityException() meta, nodes, i, s = args if s is not None: return Seq(meta, nodes, i, s) for j in range(i, len(nodes)): if nodes[j] is not None: ns = nodes[j].nodeSeq() if ns is not None: return Seq(meta, nodes, j + 1, ns) return None
def __init__(self, *args): if len(args) == 4: self._meta = None self.count = args[0] self.root = args[1] self.hasNull = args[2] self.noneValue = args[3] elif len(args) == 5: self._meta = args[0] self.count = args[1] self.root = args[2] self.hasNull = args[3] self.noneValue = args[4] else: raise ArityException()
def createNode(*args): if len(args) == 7: edit, shift, key1, val1, key2hash, key2, val2 = args elif len(args) == 6: shift, key1, val1, key2hash, key2, val2 = args edit = AtomicReference() else: raise ArityException() if shift > 64: raise Exception("Shift max reached") key1hash = hash(key1) if key1hash == key2hash: return HashCollisionNode(None, key1hash, 2, [key1, val1, key2, val2]) nbox = Box(None) nd1 = EMPTY_BITMAP_NODE \ .assocEd(edit, shift, key1hash, key1, val1, nbox) nd2 = nd1.assocEd(edit, shift, key2hash, key2, val2, nbox) return nd2
def keyword(*args): if len(args) == 1: if isinstance(args[0], Symbol): sym = args[0] if sym.meta() is not None: sym = sym.withMeta(None) k = Keyword(sym) interned.mutate(lambda old: old if sym in old else old.assoc(sym, k)) return interned.get()[sym] elif isinstance(args[0], (str, unicode)): return keyword(symbol(args[0])) else: raise InvalidArgumentException() elif len(args) == 2: return keyword(symbol(*args)) else: raise ArityException()
def __init__(self, *args): """Instantiate a PersistentHashMap args must be one of * int, INode, bool, object * IPersistentMap, int, INode bool object """ if len(args) == 4: self._meta = None # IPersistentMap self.count = args[0] # int self.root = args[1] # INode self.hasNull = args[2] # bool self.noneValue = args[3] # object elif len(args) == 5: self._meta = args[0] self.count = args[1] self.root = args[2] self.hasNull = args[3] self.noneValue = args[4] else: raise ArityException()
def createNodeSeq(*args): if len(args) == 1: if len(args[0]) == 0: return None return createNodeSeq(args[0], 0, None) if len(args) != 3: raise ArityException() array, i, s = args if s is not None: return NodeSeq(None, array, i, s) for j in range(i, len(array), 2): if array[j] is not None: return NodeSeq(None, array, j, None) node = array[j+1] if node is not None: nodeSeq = node.nodeSeq() if nodeSeq is not None: return NodeSeq(None, array, j + 2, nodeSeq) return None
def __init__(self, *args): """Instantiate a PersistentVector args must be one of: * int, int, Node, list * IPersistentHashMap, int, int, Node, list Else an ArityException will be raised. """ if len(args) == 4: cnt, shift, root, tail = args meta = None elif len(args) == 5: meta, cnt, shift, root, tail = args else: raise ArityException() self._meta = meta self._cnt = cnt self._shift = shift self._root = root self._tail = tail
def __init__(self, *args): """Instantiate a Cons. args must be one of: * object, ISeq head and tail, respectively * IPersistentMap, object, ISeq meta data, head and tail Else an ArityException will be raised.""" if len(args) == 2: self._meta = None self._first = args[0] self._more = args[1] elif len(args) == 3: self._meta = args[0] self._first = args[1] self._more = args[2] else: raise ArityException()
def __call__(self, *args): if len(args) != 1: raise ArityException() return self.impl[args[0]]
def __call__(self, *args, **kwargs): raise ArityException("Attempting to call unbound fn: {0}".format( self.v))
def __call__(self, *args, **kwargs): raise ArityException("Attempting to call unbound fn:" + str(self.v))