public static Var intern(Namespace ns, Symbol sym) { return ns.intern(sym); }
public static Var intern(Namespace ns, Symbol sym, object root) { return intern(ns, sym, root, true); }
public static Var intern(Namespace ns, Symbol sym, object root, bool replaceRoot) { Var dvout = ns.intern(sym); if (!dvout.hasRoot() || replaceRoot) dvout.bindRoot(root); return dvout; }
/// <summary> /// Construct a var in a given namespace with a given name. /// </summary> /// <param name="ns">The namespace.</param> /// <param name="sym">The var.</param> internal Var(Namespace ns, Symbol sym) { _ns = ns; _sym = sym; _threadBound = new AtomicBoolean(false); _root = new Unbound(this); setMeta(PersistentHashMap.EMPTY); }
/// <summary> /// Construct a var in a given namespace with a given name and root value. /// </summary> /// <param name="ns">The namespace.</param> /// <param name="sym">The var.</param> /// <param name="root">The root value.</param> Var(Namespace ns, Symbol sym, object root) : this(ns, sym) { _root = root; ++_rev; }
public static Namespace namespaceFor(Namespace inns, Symbol sym) { //note, presumes non-nil sym.ns // first check against currentNS' aliases... Symbol nsSym = Symbol.create(sym.Namespace); Namespace ns = inns.LookupAlias(nsSym); if (ns == null) { // ...otherwise check the Namespaces map. ns = Namespace.find(nsSym); } return ns; }
VarSerializationHelper(SerializationInfo info, StreamingContext context) { _ns = (Namespace)info.GetValue("_ns", typeof(Namespace)); _sym = (Symbol)info.GetValue("_sym", typeof(Symbol)); }
/// <summary> /// Find or create a namespace named by the symbol. /// </summary> /// <param name="name">The symbol naming the namespace.</param> /// <returns>An existing or new namespace</returns> public static Namespace findOrCreate(Symbol name) { Namespace ns = _namespaces.Get(name); if (ns != null) return ns; Namespace newns = new Namespace(name); ns = _namespaces.PutIfAbsent(name, newns); return ns == null ? newns : ns; }
/// <summary> /// Add an alias for a namespace. /// </summary> /// <param name="alias">The alias for the namespace.</param> /// <param name="ns">The namespace being aliased.</param> /// <remarks>Lowercase name for core.clj compatibility</remarks> public void addAlias(Symbol alias, Namespace ns) { if (alias == null || ns == null) throw new NullReferenceException("Expecting Symbol + Namespace"); IPersistentMap map = Aliases; // race condition while (!map.containsKey(alias)) { IPersistentMap newMap = map.assoc(alias, ns); _aliases.CompareAndSet(map, newMap); map = Aliases; } // you can rebind an alias, but only to the initially-aliased namespace if (!map.valAt(alias).Equals(ns)) throw new InvalidOperationException(String.Format("Alias {0} already exists in namespace {1}, aliasing {2}", alias, _name, map.valAt(alias))); }
public static Var intern(Symbol nsName, Symbol sym) { Namespace ns = Namespace.findOrCreate(nsName); return(intern(ns, sym)); }
/// <summary> /// Construct a var in a given namespace with a given name. /// </summary> /// <param name="ns">The namespace.</param> /// <param name="sym">The var.</param> internal Var(Namespace ns, Symbol sym) { _ns = ns; _sym = sym; _count = new AtomicInteger(); _root = _rootUnboundValue; setMeta(PersistentHashMap.EMPTY); }
public static Var intern(Namespace ns, Symbol sym, object root) { return(intern(ns, sym, root, true)); }
public static Var intern(Namespace ns, Symbol sym) { return(ns.intern(sym)); }
private static object ResolveIn(Namespace n, Symbol symbol, bool allowPrivate) { // note: ns-qualified vars must already exist if (symbol.Namespace != null) { Namespace ns = NamespaceFor(n, symbol); if (ns == null) throw new Exception("No such namespace: " + symbol.Namespace); Var v = ns.FindInternedVar(Symbol.create(symbol.Name)); if (v == null) throw new Exception("No such var: " + symbol); else if (v.Namespace != CurrentNamespace && !v.IsPublic && !allowPrivate) throw new InvalidOperationException(string.Format("var: {0} is not public", symbol)); return v; } else if (symbol.Name.IndexOf('.') > 0 || symbol.Name[0] == '[') return RT.classForName(symbol.Name); else if (symbol.Equals(NS)) return RT.NS_VAR; else if (symbol.Equals(IN_NS)) return RT.IN_NS_VAR; else { object o = n.GetMapping(symbol); if (o == null) { if (RT.booleanCast(RT.ALLOW_UNRESOLVED_VARS.deref())) return symbol; else throw new Exception(string.Format("Unable to resolve symbol: {0} in this context", symbol)); } return o; } }
private static object ResolveIn(Namespace n, Symbol symbol, bool allowPrivate) { // note: ns-qualified vars must already exist if (symbol.Namespace != null) { Namespace ns = namespaceFor(n, symbol); if (ns == null) throw new InvalidOperationException("No such namespace: " + symbol.Namespace); Var v = ns.FindInternedVar(Symbol.intern(symbol.Name)); if (v == null) throw new InvalidOperationException("No such var: " + symbol); else if (v.Namespace != CurrentNamespace && !v.isPublic && !allowPrivate) throw new InvalidOperationException(string.Format("var: {0} is not public", symbol)); return v; } else if (symbol.Name.IndexOf('.') > 0 || symbol.Name[symbol.Name.Length - 1] == ']') return RT.classForNameE(symbol.Name); else if (symbol.Equals(NsSym)) return RT.NSVar; else if (symbol.Equals(InNsSym)) return RT.InNSVar; else { if (Util.equals(symbol, CompileStubSymVar.get())) return CompileStubClassVar.get(); object o = n.GetMapping(symbol); if (o == null) { if (RT.booleanCast(RT.AllowUnresolvedVarsVar.deref())) return symbol; else throw new InvalidOperationException(string.Format("Unable to resolve symbol: {0} in this context", symbol)); } return o; } }
// core.clj compatibility public static object maybeResolveIn(Namespace n, Symbol symbol) { // note: ns-qualified vars must already exist if (symbol.Namespace != null) { Namespace ns = NamespaceFor(n, symbol); if (ns == null) return null; Var v = ns.FindInternedVar(Symbol.create(symbol.Name)); if (v == null) return null; return v; } else if (symbol.Name.IndexOf('.') > 0 || symbol.Name[0] == '[') return RT.classForName(symbol.Name); else if (symbol.Equals(NS)) return RT.NS_VAR; else if (symbol.Equals(IN_NS)) return RT.IN_NS_VAR; else { object o = n.GetMapping(symbol); return o; } }
public static object maybeResolveIn(Namespace n, Symbol symbol) { // note: ns-qualified vars must already exist if (symbol.Namespace != null) { Namespace ns = namespaceFor(n, symbol); if (ns == null) return null; Var v = ns.FindInternedVar(Symbol.intern(symbol.Name)); if (v == null) return null; return v; } else if (symbol.Name.IndexOf('.') > 0 && !symbol.Name.EndsWith(".") || symbol.Name[symbol.Name.Length - 1] == ']') /// JAVA: symbol.Name[0] == '[') return RT.classForNameE(symbol.Name); else if (symbol.Equals(NsSym)) return RT.NSVar; else if (symbol.Equals(InNsSym)) return RT.InNSVar; else { object o = n.GetMapping(symbol); return o; } }
public static Namespace NamespaceFor(Namespace n, Symbol symbol) { // Note: presumes non-nil sym.ns // first check against CurrentNamespace's aliases Symbol nsSym = Symbol.create(symbol.Namespace); Namespace ns = n.LookupAlias(nsSym); if (ns == null) // otherwise, check the namespaces map ns = Namespace.find(nsSym); return ns; }
#pragma warning restore 649 #region IObjectReference Members public object GetRealObject(StreamingContext context) { return(Namespace.findOrCreate(_name)); }