assoc() public method

Add a new key/value pair.
Overwrites an exising value for the key, if present.
public assoc ( object key, object val ) : IPersistentMap
key object The key
val object The value
return IPersistentMap
Example #1
0
        public static PersistentTreeMap create(IComparer comp, ISeq items)
        {
            IPersistentMap ret = new PersistentTreeMap(comp);

            for (; items != null; items = items.next().next())
            {
                if (items.next() == null)
                {
                    throw new ArgumentException(string.Format("No value supplied for key: {0}", items.first()));
                }
                ret = ret.assoc(items.first(), RT.second(items));
            }
            return((PersistentTreeMap)ret);
        }
Example #2
0
            static Symbol registerArg(int n)
            {
                PersistentTreeMap argsyms = (PersistentTreeMap)ARG_ENV.deref();

                if (argsyms == null)
                {
                    throw new InvalidOperationException("arg literal not in #()");
                }
                Symbol ret = (Symbol)argsyms.valAt(n);

                if (ret == null)
                {
                    ret = garg(n);
                    ARG_ENV.set(argsyms.assoc(n, ret));
                }
                return(ret);
            }
 /// <summary>
 /// Create a <see cref="PersistentTreeMap">PersistentTreeMap</see> from a comparison method
 /// an <see cref="ISeq">ISeq</see> of alternating keys and values.
 /// </summary>
 /// <param name="comp">A comparison method.</param>
 /// <param name="items">The <see cref="ISeq">ISeq</see>  of alternating keys and values.</param>
 /// <returns>A <see cref="PersistentTreeMap">PersistentTreeMap</see>.</returns>
 public static PersistentTreeMap create(IComparer comp, ISeq items)
 {
     IPersistentMap ret = new PersistentTreeMap(comp);
     for (; items != null; items = items.rest().rest())
     {
         if (items.rest() == null)
             throw new ArgumentException(string.Format("No value supplied for key: %s", items.first()));
         ret = ret.assoc(items.first(), items.rest().first());
     }
     return (PersistentTreeMap)ret;
 }