Equals() public method

Determine if an object is equal to this symbol.
Uses value semantics, value determined by namespace name and symbol name.
public Equals ( object obj ) : bool
obj object The object to compare to.
return bool
Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            //if (o == null || GetType() != o.GetType()) return false;

            TaggedLiteral that = obj as TaggedLiteral;

            if (that == null)
            {
                return(false);
            }

            if (_form != null ? !_form.Equals(that._form) : that._form != null)
            {
                return(false);
            }
            if (_tag != null ? !_tag.Equals(that._tag) : that._tag != null)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
 public static Namespace remove(Symbol name)
 {
     if (name.Equals(RT.ClojureNamespace.Name))
     {
         throw new ArgumentException("Cannot remove clojure namespace");
     }
     return(_namespaces.Remove(name));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Determines if an object is equal to this keyword.  Value semantics.
        /// </summary>
        /// <param name="obj">The object to compare to.</param>
        /// <returns><value>true</value> if equal; <value>false</value> otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            return(obj is Keyword keyword && _sym.Equals(keyword.Symbol));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines if an object is equal to this keyword.  Value semantics.
        /// </summary>
        /// <param name="obj">The object to compare to.</param>
        /// <returns><value>true</value> if equal; <value>false</value> otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            Keyword keyword = obj as Keyword;

            if (ReferenceEquals(keyword, null))
            {
                return(false);
            }

            return(_sym.Equals(keyword.Symbol));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determines if an object is equal to this keyword.  Value semantics.
        /// </summary>
        /// <param name="obj">The object to compare to.</param>
        /// <returns><value>true</value> if equal; <value>false</value> otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            Keyword keyword = obj as Keyword;

            if (keyword == null)
            {
                return(false);
            }

            return(_sym.Equals(keyword.Symbol));
        }
Exemplo n.º 6
0
        internal static Type[] CreateTypeArray(ISeq seq)
        {
            List <Type> types = new List <Type>();

            for (ISeq s = seq?.seq(); s != null; s = s.next())
            {
                Object o       = s.first();
                Type   oAsType = o as Type;
                if (oAsType != null)
                {
                    types.Add(oAsType);
                }
                else if (o is ISeq)
                {
                    object first         = RT.first(o);
                    Symbol firstAsSymbol = first as Symbol;
                    if (firstAsSymbol == null || !firstAsSymbol.Equals(HostExpr.ByRefSym))
                    {
                        throw new ArgumentException("First element of parameter definition is not by-ref");
                    }

                    Type secondAsType = RT.second(o) as Type;

                    if (secondAsType == null)
                    {
                        throw new ArgumentException("by-ref must be paired with a type");
                    }

                    types.Add(secondAsType.MakeByRefType());
                }
                else
                {
                    throw new ArgumentException("Bad parameter definition");
                }
            }

            if (types.Count == 0)
            {
                return(Type.EmptyTypes);
            }

            return(types.ToArray <Type>());
        }
Exemplo n.º 7
0
            protected override object Read(PushbackTextReader r, char eq)
            {
                if (!RT.booleanCast(RT.READEVAL.deref()))
                {
                    throw new Exception("EvalReader not allowed when *read-eval* is false.");
                }
                Object o = read(r, true, null, true);

                if (o is Symbol)
                {
                    return(RT.classForName(o.ToString()));
                }
                else if (o is IPersistentList)
                {
                    Symbol fs = (Symbol)RT.first(o);
                    if (fs.Equals(THE_VAR))
                    {
                        Symbol vs = (Symbol)RT.second(o);
                        return(RT.var(vs.Namespace, vs.Name));  //Compiler.resolve((Symbol) RT.second(o),true);
                    }
                    if (fs.Name.EndsWith("."))
                    {
                        Object[] args = RT.toArray(RT.next(o));
                        return(Reflector.InvokeConstructor(RT.classForName(fs.Name.Substring(0, fs.Name.Length - 1)), args));
                    }
                    if (Compiler.NamesStaticMember(fs))
                    {
                        Object[] args = RT.toArray(RT.next(o));
                        return(Reflector.InvokeStaticMethod(fs.Namespace, fs.Name, args));
                    }
                    Object v = Compiler.maybeResolveIn(Compiler.CurrentNamespace, fs);
                    if (v is Var)
                    {
                        return(((IFn)v).applyTo(RT.next(o)));
                    }
                    throw new Exception("Can't resolve " + fs);
                }
                else
                {
                    throw new ArgumentException("Unsupported #= form");
                }
            }
Exemplo n.º 8
0
        internal static Var LookupVar(Symbol sym, bool internNew)
        {
            Var var = null;

            // Note: ns-qualified vars in other namespaces must exist already
            if (sym.Namespace != null)
            {
                Namespace ns = Compiler.NamespaceFor(sym);
                if (ns == null)
                    return null;
                Symbol name = Symbol.create(sym.Name);
                if (internNew && ns == CurrentNamespace)
                    var = CurrentNamespace.intern(name);
                else
                    var = ns.FindInternedVar(name);
            }
            else if (sym.Equals(NS))
                var = RT.NS_VAR;
            else if (sym.Equals(IN_NS))
                var = RT.IN_NS_VAR;
            else
            {
                // is it mapped?
                Object o = CurrentNamespace.GetMapping(sym);
                if (o == null)
                {
                    // introduce a new var in the current ns
                    if (internNew)
                        var = CurrentNamespace.intern(Symbol.create(sym.Name));
                }
                else if (o is Var)
                    var = (Var)o;
                else
                    throw new Exception(string.Format("Expecting var, but {0} is mapped to {1}", sym, o));
            }
            if (var != null)
                RegisterVar(var);
            return var;
        }
Exemplo n.º 9
0
        // 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;
            }
        }
Exemplo n.º 10
0
        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;
            }
        }
Exemplo n.º 11
0
        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;
            }
        }
Exemplo n.º 12
0
        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;
            }
        }
Exemplo n.º 13
0
        internal static Var LookupVar(Symbol sym, bool internNew, Boolean registerMacro)
        {
            Var var = null;

            // Note: ns-qualified vars in other namespaces must exist already
            if (sym.Namespace != null)
            {
                Namespace ns = Compiler.namespaceFor(sym);
                if (ns == null)
                    return null;
                Symbol name = Symbol.intern(sym.Name);
                if (internNew && ns == CurrentNamespace)
                    var = CurrentNamespace.intern(name);
                else
                    var = ns.FindInternedVar(name);
            }
            else if (sym.Equals(NsSym))
                var = RT.NSVar;
            else if (sym.Equals(InNsSym))
                var = RT.InNSVar;
            else
            {
                // is it mapped?
                Object o = CurrentNamespace.GetMapping(sym);
                if (o == null)
                {
                    // introduce a new var in the current ns
                    if (internNew)
                        var = CurrentNamespace.intern(Symbol.intern(sym.Name));
                }
                else
                {
                    var = o as Var;
                    if (var == null)
                        throw new InvalidOperationException(string.Format("Expecting var, but {0} is mapped to {1}", sym, o));
                }
            }
            if (var != null && (!var.IsMacro || registerMacro))
                RegisterVar(var);
            return var;
        }
Exemplo n.º 14
0
 /// <summary>
 /// Remove a namespace (by name).
 /// </summary>
 /// <param name="name">The (Symbol) name of the namespace to remove.</param>
 /// <returns>The namespace that was removed.</returns>
 /// <remarks>Trying to remove the clomure namespace throws an exception.</remarks>
 public static Namespace remove(Symbol name)
 {
     if (name.Equals(RT.CLOJURE_NS.Name))
         throw new ArgumentException("Cannot remove clojure namespace");
     return _namespaces.Remove(name);
 }