public void removeAlias(Symbol alias) { IPersistentMap map = Aliases; while (map.containsKey(alias)) { IPersistentMap newMap = map.without(alias); _aliases.CompareAndSet(map, newMap); map = Aliases; } }
public void WithoutOnMissingKeyIsIdentity() { Dictionary <int, string> d = new Dictionary <int, string>(); d[3] = "a"; d[5] = "b"; d[7] = "c"; IPersistentMap m1 = PersistentArrayMap.create(d); IPersistentMap m2 = m1.without(4); Expect(m2, SameAs(m1)); }
object DrawDynamicWidget(object key, object val) { if (val is IPersistentMap) { IPersistentMap map = val as IPersistentMap; EditorGUILayout.LabelField(key.ToString(), "{"); EditorGUI.indentLevel++; foreach (var entry in map) { object oldKey = entry.key(); GUILayout.BeginHorizontal(); object newKey = LoadString(EditorGUILayout.TextField(PrStr(entry.key()))); object newVal = LoadString(EditorGUILayout.TextField(PrStr(entry.val()))); map = map.without(oldKey); if (!GUILayout.Button("X", EditorStyles.miniButton)) { map = map.assoc(newKey, newVal); } GUILayout.EndHorizontal(); } if (GUILayout.Button("+", EditorStyles.miniButton)) { map = map.assoc("", ""); } EditorGUI.indentLevel--; return(map); } else if (val is IPersistentVector) { IPersistentVector vector = val as IPersistentVector; EditorGUILayout.LabelField(key.ToString(), "["); EditorGUI.indentLevel++; for (int i = 0; i < vector.count(); i++) { vector = vector.assocN(i, DrawDynamicWidget(i.ToString(), vector.nth(i))); } // EditorGUILayout.LabelField("", "]"); EditorGUI.indentLevel--; return(vector); } else { return(RT.var("clojure.core", "read-string").invoke(EditorGUILayout.TextField(key.ToString(), (string)RT.var("clojure.core", "pr-str").invoke(val)))); } }
public void WithoutOnExistingKeyRemovesKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[3] = "a"; d[5] = "b"; d[7] = "c"; IPersistentMap m1 = PersistentArrayMap.create(d); IPersistentMap m2 = m1.without(5); Expect(m1.count(), EqualTo(3)); Expect(m1.valAt(5), EqualTo("b")); Expect(m2.count(), EqualTo(2)); Expect(m2.containsKey(5), False); }
public void unmap(Symbol sym) { if (sym.Namespace != null) { throw new ArgumentException("Can't unintern a namespace-qualified symbol"); } IPersistentMap map = Mappings; while (map.containsKey(sym)) { IPersistentMap newMap = map.without(sym); _mappings.CompareAndSet(map, newMap); map = Mappings; } }
public static Expr Parse(ParserContext pcon, ISeq form, string name) { ISeq origForm = form; FnExpr fn = new FnExpr(Compiler.TagOf(form)); fn._src = form; if (((IMeta)form.first()).meta() != null) { fn._onceOnly = RT.booleanCast(RT.get(RT.meta(form.first()), KW_ONCE)); } fn.ComputeNames(form, name); List <string> prims = new List <string>(); //arglist might be preceded by symbol naming this fn if (RT.second(form) is Symbol) { Symbol nm = (Symbol)RT.second(form); fn._thisName = nm.Name; fn._isStatic = false; // RT.booleanCast(RT.get(nm.meta(), Compiler.STATIC_KEY)); form = RT.cons(Compiler.FnSym, RT.next(RT.next(form))); } // Normalize body //now (fn [args] body...) or (fn ([args] body...) ([args2] body2...) ...) //turn former into latter if (RT.second(form) is IPersistentVector) { form = RT.list(Compiler.FnSym, RT.next(form)); } fn.SpanMap = (IPersistentMap)Compiler.SourceSpanVar.deref(); GenContext newContext = null; GenContext context = Compiler.CompilerContextVar.deref() as GenContext ?? Compiler.EvalContext; newContext = context.WithNewDynInitHelper(fn.InternalName + "__dynInitHelper_" + RT.nextID().ToString()); Var.pushThreadBindings(RT.map(Compiler.CompilerContextVar, newContext)); try { try { Var.pushThreadBindings(RT.mapUniqueKeys( Compiler.ConstantsVar, PersistentVector.EMPTY, Compiler.ConstantIdsVar, new IdentityHashMap(), Compiler.KeywordsVar, PersistentHashMap.EMPTY, Compiler.VarsVar, PersistentHashMap.EMPTY, Compiler.KeywordCallsitesVar, PersistentVector.EMPTY, Compiler.ProtocolCallsitesVar, PersistentVector.EMPTY, Compiler.VarCallsitesVar, Compiler.EmptyVarCallSites(), Compiler.NoRecurVar, null)); SortedDictionary <int, FnMethod> methods = new SortedDictionary <int, FnMethod>(); FnMethod variadicMethod = null; for (ISeq s = RT.next(form); s != null; s = RT.next(s)) { FnMethod f = FnMethod.Parse(fn, (ISeq)RT.first(s), fn._isStatic); if (f.IsVariadic) { if (variadicMethod == null) { variadicMethod = f; } else { throw new ParseException("Can't have more than 1 variadic overload"); } } else if (!methods.ContainsKey(f.RequiredArity)) { methods[f.RequiredArity] = f; } else { throw new ParseException("Can't have 2 overloads with the same arity."); } if (f.Prim != null) { prims.Add(f.Prim); } } if (variadicMethod != null && methods.Count > 0 && methods.Keys.Max() >= variadicMethod.NumParams) { throw new ParseException("Can't have fixed arity methods with more params than the variadic method."); } if (fn._isStatic && fn.Closes.count() > 0) { throw new ParseException("static fns can't be closures"); } IPersistentCollection allMethods = null; foreach (FnMethod method in methods.Values) { allMethods = RT.conj(allMethods, method); } if (variadicMethod != null) { allMethods = RT.conj(allMethods, variadicMethod); } fn._methods = allMethods; fn._variadicMethod = variadicMethod; fn.Keywords = (IPersistentMap)Compiler.KeywordsVar.deref(); fn.Vars = (IPersistentMap)Compiler.VarsVar.deref(); fn.Constants = (PersistentVector)Compiler.ConstantsVar.deref(); fn.KeywordCallsites = (IPersistentVector)Compiler.KeywordCallsitesVar.deref(); fn.ProtocolCallsites = (IPersistentVector)Compiler.ProtocolCallsitesVar.deref(); fn.VarCallsites = (IPersistentSet)Compiler.VarCallsitesVar.deref(); fn._constantsID = RT.nextID(); } finally { Var.popThreadBindings(); } IPersistentMap fmeta = RT.meta(origForm); if (fmeta != null) { fmeta = fmeta.without(RT.LineKey).without(RT.ColumnKey).without(RT.SourceSpanKey).without(RT.FileKey); } fn._hasMeta = RT.count(fmeta) > 0; IPersistentVector primTypes = PersistentVector.EMPTY; foreach (string typename in prims) { primTypes = primTypes.cons(Type.GetType(typename)); } fn.Compile( fn.IsVariadic ? typeof(RestFn) : typeof(AFunction), null, primTypes, fn._onceOnly, newContext); if (fn.SupportsMeta) { return(new MetaExpr(fn, MapExpr.Parse(pcon.EvalOrExpr(), fmeta))); } else { return(fn); } } finally { if (newContext != null) { Var.popThreadBindings(); } } }
public IRef removeWatch(object key) { _watches = _watches.without(key); return(this); }