コード例 #1
0
  // Taken from clojure.lang.APersistentMap
  public IPersistentCollection cons(Object o) {
    if (o instanceof Map.Entry) {
      Map.Entry e = (Map.Entry) o;
      return assoc(e.getKey(), e.getValue());
    } else if (o instanceof IPersistentVector) {
      IPersistentVector v = (IPersistentVector) o;
      if (v.count() != 2) {
        throw new IllegalArgumentException("Vector arg to temporal conj must be a pair");
      }
      return assoc(v.nth(0), v.nth(1));
    }

    IPersistentMap ret = this;
    for (ISeq es = RT.seq(o); es != null; es = es.next()) {
      Map.Entry e = (Map.Entry) es.first();
      ret = ret.assoc(e.getKey(), e.getValue());
    }
    return ret;
  }
コード例 #2
0
  private Object find00(String name) {
    for (ISeq seq = Namespace.all(); seq != null; seq = seq.next()) {
      Namespace ns = (Namespace) seq.first();
      String nsName = ns.toString();
      if (nsName.startsWith("clojure")) continue;

      for (ISeq mseq = ns.getMappings().seq(); mseq != null; mseq = mseq.next()) {
        IMapEntry e = (IMapEntry) mseq.first();
        String k = e.getKey().toString();
        if (k.equals(name)) {
          Object val = e.getValue();
          if (val.toString().startsWith("#'clojure")) continue;
          if (val instanceof Var) {
            val = ((Var) val).deref();
            return val;
          }
        }
      }
    }

    return null;
  }