Package clojure.lang

Examples of clojure.lang.Symbol


                {
                    throw new IllegalArgumentException(String.format("Method %s may not be void when bridging to Clojure functions.",
                            desc));
                }

                final Symbol symbol = mapper.mapMethod(namespace, method);

                tracker.run(String.format("Mapping %s method %s to Clojure function %s",
                        interfaceType.getName(),
                        desc.toShortString(),
                        symbol.toString()), new Runnable()
                {
                    @Override
                    public void run()
                    {

                        Symbol namespaceSymbol = Symbol.create(symbol.getNamespace());

                        REQUIRE.invoke(namespaceSymbol);

                        IFn clojureFunction = Clojure.var(symbol);
View Full Code Here


                {
                    throw new IllegalArgumentException(String.format("Method %s may not be void when bridging to Clojure functions.",
                            desc));
                }

                final Symbol symbol = mapper.mapMethod(namespace, method);

                tracker.run(String.format("Mapping %s method %s to Clojure function %s",
                        interfaceType.getName(),
                        desc.toShortString(),
                        symbol.toString()), new Runnable()
                {
                    public void run()
                    {
                        Symbol namespaceSymbol = Symbol.create(symbol.getNamespace());

                        REQUIRE.invoke(namespaceSymbol);

                        Var var = Var.find(symbol);
View Full Code Here

    tempDependents=updateBackDeps(key,tempDependents,oldDeps,free);
   
    // Compute which symbols cannot yet be bound from the current environment
    IPersistentSet unbound=free;
    for (ISeq s=RT.seq(unbound);s!=null; s=s.next()) {
      Symbol sym=(Symbol) s.first();
      if (isBound(sym)) {
        unbound=unbound.disjoin(sym);
      }
    }
   
View Full Code Here

      IPersistentSet oldDeps, IPersistentSet newDeps) {
    if (oldDeps==newDeps) return backDeps;
   
    // add new back dependencies
    for (ISeq s=newDeps.seq(); s!=null; s=s.next()) {
      Symbol sym=(Symbol)s.first();
      if (oldDeps.contains(sym)) continue;
      IPersistentSet bs=(IPersistentSet) backDeps.valAt(sym);
      if (bs==null) bs=PersistentHashSet.EMPTY;
      backDeps=backDeps.assoc(sym, bs.cons(key));
    }
   
    // remove old back dependencies
    for (ISeq s=oldDeps.seq(); s!=null; s=s.next()) {
      Symbol sym=(Symbol)s.first();
      if (newDeps.contains(sym)) continue;
      IPersistentSet bs=(IPersistentSet) backDeps.valAt(sym);
      bs=bs.disjoin(key);
      if (bs.count()==0) {
        backDeps=backDeps.without(sym);
View Full Code Here

  @SuppressWarnings("unchecked")
  public void validate() {
    for (Object o : map) {
      Map.Entry<Symbol, Mapping> ent=(Entry<Symbol, Mapping>) o;
      Symbol key=ent.getKey();
      Mapping m=ent.getValue();
      if (m==null) throw new KissException("Unexcpected null mapping for symbol: "+key);
     
      // check free symbols equals dependencies
      IPersistentSet free=m.getExpression().accumulateFreeSymbols(PersistentHashSet.EMPTY);
      IPersistentSet ds=(IPersistentSet) dependencies.valAt(key);
      if (!free.equiv(ds)) {
        throw new KissException("Mismatched dependencies for symbol: "+key+" free="+free+" deps="+ds);
      }
     
      // check unbound dependencies are consistent
      IPersistentSet unbound=m.getUnbound();
      for (ISeq s=unbound.seq(); s!=null; s=s.next()) {
        Symbol sym=(Symbol)s.first();
        if (isBound(sym)) throw new KissException("Expected symbol to be unbound: "+sym);
      }
     
      // check reverse dependencies
      for (ISeq s=ds.seq(); s!=null; s=s.next()) {
        Symbol sym=(Symbol)s.first();
        IPersistentSet bs=(IPersistentSet) dependents.valAt(sym);
        if (!bs.contains(key)) throw new KissException("Missing back dependency from "+sym+"=>"+key);
      }
    }
  }
View Full Code Here

    throw new KissException("Unrecognised type symbol: "+sym);
  }

  private static Type analyseTypeSeq(ISeq s) {
    List<Object> al=KissUtils.asList(s);
    Symbol sym=(Symbol) al.get(0);
    if (sym.equals(Symbols.U)) {
      Type[] types=analyseSequenceOfTypes(al,1,al.size()-1);
      return Union.create(types);
    } else if (sym.equals(Symbols.I)) {
      Type[] types=analyseSequenceOfTypes(al,1,al.size()-1);
      return Intersection.create(types);
    }
    throw new KissException("Unrecognised type form: "+s);   
  }
View Full Code Here

    int n=form.count();
    if (n==0) return Constant.create(form);
    Object first=form.first();
   
    if (first instanceof Symbol) {
      Symbol s=(Symbol)first;
      if (s.equals(Symbols.LET)) {
        IPersistentVector v=KissUtils.expectVector(RT.second(form));
        int vc=v.count();
        if ((vc&1)!=0) throw new KissException("let requires an even number of binding forms");
       
        // start with expression body
        Expression e = analyse(RT.nth(form, 2));
       
        for (int i=vc-2; i>=0; i-=2) {
          Symbol sym=KissUtils.expectSymbol(v.nth(i));
          Expression exp=analyse(v.nth(i+1));
          e= Let.create(sym, exp, e);
        }
        return e;
      }
     
      if (s.equals(Symbols.LOOP)) {
        IPersistentVector v=KissUtils.expectVector(RT.second(form));
        int vc=v.count();
        if ((vc&1)!=0) throw new KissException("let requires an even number of binding forms");
       
        Symbol[] syms=new Symbol[vc/2];
        Expression[] initials=new Expression[vc/2];
       
        for (int i=0; i<vc; i+=2) {
          syms[i]=KissUtils.expectSymbol(v.nth(i));
          initials[i+i]=analyse(v.nth(i+1));
        }
        Expression body = analyse(RT.nth(form, 2));
        return Loop.create(syms, initials, body);
      }
     
      if (s.equals(Symbols.RECUR)) {
        int vc=n-1;
        Expression[] values=new Expression[vc];
       
        for (int i=0; i<vc; i++) {
          values[i]=analyse(RT.nth(form,(i+1)));
        }
        return Recur.create(values);
      }
     
      if (s.equals(Symbols.RETURN)) {
        Expression value=analyse(RT.nth(form,1));
        return Return.create(value);
      }
     
      if (s.equals(Symbols.IF)) {
        switch (n) {
        case 4:
          return If.create(analyse(RT.nth(form, 1)), analyse(RT.nth(form, 2)), analyse(RT.nth(form, 3)));
        case 3:
          return If.create(analyse(RT.nth(form, 1)), analyse(RT.nth(form, 2)),Constant.NULL);
        default:
          throw new KissException("Wrong number of forms in if expression: "+n);
        }   
      }
     
      if (s.equals(Symbols.INSTANCE)) {
        switch (n) {
        case 3:
          return InstanceOf.create(analyseType(RT.nth(form, 1)), analyse(RT.nth(form, 2)));
        default:
          throw new KissException("Wrong number of forms in instance? expression: "+n);
        }   
      }
     
      if (s.equals(Symbols.DEF)) {
        if (n!=3) throw new KissException("Wrong number of forms in def expression: "+n);
        Symbol sym=(Symbol)RT.nth(form,1);
        return Def.create(sym,analyse(RT.nth(form, 2)));   
      }

      if (s.equals(Symbols.DO)) {
        Expression[] exps=new Expression[n-1];
        for (int i=1; i<n; i++) {
          exps[i-1]=analyse(RT.nth(form, i));
        }
        return Do.create(exps);
      }
     
      if (s.equals(Symbols.FN)) {
        IPersistentVector v=KissUtils.expectVector(RT.second(form));
        int arity=v.count();
        Symbol[] syms=new Symbol[arity];
        Type[] types=new Type[arity];
        for (int i=0; i<arity; i++) {
          Symbol paramSym=(Symbol)v.nth(i);
          syms[i]=paramSym;
          Type paramType=Type.resolveTag(s);
          types[i]=paramType;
        }
        Expression body=analyse(RT.nth(form, 2));
View Full Code Here

*/
public class Clojure {
    private Clojure() {}

    private static Symbol asSym(Object o) {
        Symbol s;
        if (o instanceof String) {
            s = Symbol.intern((String) o);
        else {
            s = (Symbol) o;
        }
View Full Code Here

     *
     * @param qualifiedName  a String or clojure.lang.Symbol
     * @return               a clojure.lang.IFn
     */
    public static IFn var(Object qualifiedName) {
        Symbol s = asSym(qualifiedName);
        return var(s.getNamespace(), s.getName());
    }
View Full Code Here

  public static void main(String... args) {
    String jlineLog = System.getenv("JLINE_LOGGING");
    if (jlineLog != null) {
      System.setProperty("jline.internal.Log." + jlineLog, "true");
    }
    Symbol ns = Symbol.create("reply.main");
    RT.var("clojure.core", "require").invoke(ns);
    RT.var("reply.main", "-main").applyTo(RT.seq(args));
  }
View Full Code Here

TOP

Related Classes of clojure.lang.Symbol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.