Package clojure.lang

Examples of clojure.lang.IPersistentSet


    }

    @JRubyMethod(name={"==", "eql?", "equal?"})
    public IRubyObject equal_p(ThreadContext context, IRubyObject arg) {
        if (arg.isNil()) return context.getRuntime().getFalse();
        IPersistentSet other = null;
        if (arg.respondsTo("intersection")) {
            other = DiametricUtils.getPersistentSet(context, arg);
        } else if (arg instanceof HashSet) {
            other = convertHashSetToPersistentHashSet((HashSet)arg);
        } else if (arg instanceof DiametricSet) {
View Full Code Here


    }

    @JRubyMethod(name={"&", "intersection"})
    public IRubyObject intersection(ThreadContext context, IRubyObject arg) {
        if (!(arg.respondsTo("intersection"))) throw context.getRuntime().newArgumentError("argument should be a set");
        IPersistentSet other = (IPersistentSet)DiametricUtils.getPersistentSet(context, arg);
        try {
            Var var = DiametricService.getFn("clojure.set", "intersection");
            if (set instanceof HashSet) {
                PersistentHashSet value = convertHashSetToPersistentHashSet(set);
                return DiametricUtils.convertJavaToRuby(context, var.invoke(value, other));
View Full Code Here

    }

    @JRubyMethod(name={"|", "union"})
    public IRubyObject union(ThreadContext context, IRubyObject arg) {
        if (!(arg.respondsTo("union"))) throw context.getRuntime().newArgumentError("argument should be a set");
        IPersistentSet other = (IPersistentSet)DiametricUtils.getPersistentSet(context, arg);
        try {
            Var var = DiametricService.getFn("clojure.set", "union");
            if (set instanceof HashSet) {
                PersistentHashSet value = convertHashSetToPersistentHashSet(set);
                return DiametricSet.getDiametricSet(context, (Set)var.invoke(value, other));
View Full Code Here

    }

    @JRubyMethod(name={"-", "difference"})
    public IRubyObject difference(ThreadContext context, IRubyObject arg) {
        if (!(arg.respondsTo("difference"))) throw context.getRuntime().newArgumentError("argument should be a set");
        IPersistentSet other = (IPersistentSet)DiametricUtils.getPersistentSet(context, arg);
        try {
            Var var = DiametricService.getFn("clojure.set", "difference");
            if (set instanceof HashSet) {
                PersistentHashSet value = convertHashSetToPersistentHashSet(set);
                return DiametricSet.getDiametricSet(context, (Set)var.invoke(value, other));
View Full Code Here

   
    // manage dependency updates
    IPersistentMap tempDependencies=this.dependencies;
    IPersistentMap tempDependents=this.dependents;
   
    IPersistentSet free=body.accumulateFreeSymbols(PersistentHashSet.EMPTY);
   
    IPersistentSet oldDeps=(IPersistentSet) tempDependencies.valAt(key);
    if ((oldDeps==null)) oldDeps=PersistentHashSet.EMPTY;

    // update dependencies to match the free variables in the expression
    tempDependencies=tempDependencies.assoc(key, free);
    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);
      }
    }
   
    if (unbound.count()==0) {
      Environment newEnv=body.compute(this, bindings);
      Object value=newEnv.getResult();
      newEnv = new Environment(map.assoc(key, Mapping.createExpression(body, value, null)),tempDependencies,tempDependents,value);
     
      newEnv=updateDependents(newEnv,key);
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  private static Environment updateDependents(Environment e, Symbol key) {
    // get the set of symbols that depend directly or indirectly on the given key
    IPersistentSet ss = e.accumulateDependents(PersistentHashSet.EMPTY,key);
   
    // check if there are any dependents
    if (ss==PersistentHashSet.EMPTY) return e;
   
    for (Symbol s:((java.util.Collection<Symbol>)ss)) {
      Mapping m=(Mapping) e.map.valAt(s);
      IPersistentSet sunbound=m.getUnbound();
      if (sunbound.count()==0) {
        // TODO: update needed!
      }
    }
    return e;
   
View Full Code Here

   
  }
 
  @SuppressWarnings("unchecked")
  private IPersistentSet accumulateDependents(IPersistentSet set, Symbol key) {
    IPersistentSet ss=(IPersistentSet)(dependents.valAt(key));
    if ((ss==null)||(ss==PersistentHashSet.EMPTY)) return set;
    for (Symbol s: ((java.util.Collection<Symbol>)ss)) {
      if (!set.contains(s)) {
        set=(IPersistentSet) set.cons(s);
        accumulateDependents(set,s);
View Full Code Here

   
    // 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);
      } else {
        backDeps=backDeps.assoc(sym, bs);
      }
    }
View Full Code Here

      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

 
  @Test
  public void testSubstitutions() {
    for (Expression e:testExprs) {
      try {
        IPersistentSet free=e.accumulateFreeSymbols(PersistentHashSet.EMPTY);
        if (free.count()==0) {
          Object result=e.eval(); // should work
          assertTrue(e.getType().checkInstance(result));
        } else {
          try {
            e.eval();
View Full Code Here

TOP

Related Classes of clojure.lang.IPersistentSet

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.