Example #1
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);
            }
Example #2
0
            //static ListReader _listReader = new ListReader();

            protected override object Read(PushbackTextReader r, char lparen)
            {
                if (ARG_ENV.deref() != null)
                {
                    throw new InvalidOperationException("Nested #()s are not allowed");
                }
                try
                {
                    Var.pushThreadBindings(RT.map(ARG_ENV, PersistentTreeMap.EMPTY));
                    r.Unread('(');
                    ////object form = ReadAux(r, true, null, true);
                    object form = ReadAux(r);
                    //object form = _listReader.invoke(r, '(');

                    IPersistentVector args    = PersistentVector.EMPTY;
                    PersistentTreeMap argsyms = (PersistentTreeMap)ARG_ENV.deref();
                    ISeq rargs = argsyms.rseq();
                    if (rargs != null)
                    {
                        int higharg = (int)((IMapEntry)rargs.first()).key();
                        if (higharg > 0)
                        {
                            for (int i = 1; i <= higharg; ++i)
                            {
                                object sym = argsyms.valAt(i);
                                if (sym == null)
                                {
                                    sym = garg(i);
                                }
                                args = args.cons(sym);
                            }
                        }
                        object restsym = argsyms.valAt(-1);
                        if (restsym != null)
                        {
                            args = args.cons(Compiler._AMP_);
                            args = args.cons(restsym);
                        }
                    }
                    return(RT.list(Compiler.FN, args, form));
                }
                finally
                {
                    Var.popThreadBindings();
                }
            }