Beispiel #1
0
        public bool Equals(Symbol other)
        {
            if (other == null)
            {
                return(false);
            }
            if (Tag != other.Tag)
            {
                return(false);
            }
            switch (Tag)
            {
            case SymbolTag.Atom: return(AsAtom == other.AsAtom);

            case SymbolTag.Number: return(AsNumber == other.AsNumber);

            case SymbolTag.String: return(AsString == other.AsString);

            case SymbolTag.Quote: return(AsQuote == other.AsQuote);

            case SymbolTag.Symbols: return(AsSymbols.SequenceEqual(other.AsSymbols));

            default: throw new InexhausiveException();
            }
        }
Beispiel #2
0
        public override int GetHashCode()
        {
            switch (Tag)
            {
            case SymbolTag.Atom: return(AsAtom.GetHashCode());

            case SymbolTag.Number: return(AsNumber.GetHashCode());

            case SymbolTag.String: return(AsString.GetHashCode());

            case SymbolTag.Quote: return(AsQuote.GetHashCode());

            case SymbolTag.Symbols: return(AsSymbols.Aggregate(0, (hash, symbol) => hash ^ symbol.GetHashCode()));

            default: throw new InexhausiveException();
            }
        }