clojure.lang.Namespace类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中clojure.lang.Namespace类的一些代码示例,展示了Namespace类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Namespace类的具体详情如下:
包路径:clojure.lang.Namespace
类名称:Namespace

Namespace介绍

暂无

代码示例

代码示例来源:origin: org.dunaj/clojure

private Object readResolve() throws ObjectStreamException {
  // ensures that serialized namespaces are "deserialized" to the
  // namespace in the present runtime
  return findOrCreate(name);
}
}

代码示例来源:origin: nodebox/nodebox

for (Object item : ns.getMappings()) {
  MapEntry entry = (MapEntry) item;
  if (entry.getValue() instanceof Var) {
    Var var = (Var) entry.getValue();
    if (var.ns.toString().equals(namespace)) {
      String name = entry.getKey().toString();
      if (var.deref() instanceof IFn) {

代码示例来源:origin: apache/nifi

@Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
  try {
    // Get engine bindings and send them to Clojure
    Bindings engineBindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
    engineBindings.entrySet().forEach((entry) -> Var.intern(Namespace.findOrCreate(NAMESPACE_SYMBOL), Symbol.create(entry.getKey().intern()), entry.getValue(), true));
    Var.pushThreadBindings(
        RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref(),
            RT.IN, new LineNumberingPushbackReader(context.getReader()),
            RT.OUT, context.getWriter(),
            RT.ERR, context.getErrorWriter()));
    Object result = Compiler.load(reader);
    return result;
  } catch (Exception e) {
    throw new ScriptException(e);
  } finally {
    Namespace.remove(NAMESPACE_SYMBOL);
  }
}

代码示例来源:origin: videlalvaro/clochure

public static Var internPrivate(String nsName, String sym){
  Namespace ns = Namespace.findOrCreate(Symbol.intern(nsName));
  Var ret = intern(ns, Symbol.intern(sym));
  ret.setMeta(privateMeta);
  return ret;
}

代码示例来源:origin: videlalvaro/clochure

Object reference(Symbol sym, Object val){
  if(sym.ns != null)
    {
    throw new IllegalArgumentException("Can't intern namespace-qualified symbol");
    }
  IPersistentMap map = getMappings();
  Object o;
  while((o = map.valAt(sym)) == null)
    {
    IPersistentMap newMap = map.assoc(sym, val);
    mappings.compareAndSet(map, newMap);
    map = getMappings();
    }
  if(o == val)
    return o;

  warnOrFailOnReplace(sym, o, val);

  while(!mappings.compareAndSet(map, map.assoc(sym, val)))
    map = getMappings();

  return val;

}

代码示例来源:origin: org.dunaj/clojure

public Object invoke(Object arg1) {
    Symbol nsname = (Symbol) arg1;
    Namespace ns = Namespace.findOrCreate(nsname);
        ns.addDefaultImports();
    CURRENT_NS.set(ns);
    return ns;
  }
};

代码示例来源:origin: cosmin/IClojure

private void createUserNamespace() throws ClassNotFoundException, IOException {
  Namespace userNs = Namespace.findOrCreate(Symbol.create(null, "user"));
  RT.load("clojure/repl");
  List<String> replFns = new ArrayList<String>(Arrays.asList("source", "apropos", "dir"));
  if (!clojure1_2) {
    replFns.add("doc");
    replFns.add("find-doc");
  }
  for (String name : replFns) {
    userNs.refer(Symbol.create(null, name), var("clojure.repl", name));
  }
  if (!clojure1_2) {
    RT.load("clojure/java/javadoc");
    userNs.refer(Symbol.create(null, "javadoc"), var("clojure.java.javadoc", "javadoc"));
  }
  RT.load("clojure/pprint");
  userNs.refer(Symbol.create(null, "pprint"), var("clojure.pprint", "pprint"));
  RT.load("clj_stacktrace/repl");
  userNs.refer(Symbol.create(null, "pst"), var("clj-stacktrace.repl", "pst"));
  RT.load("cd_client/core");
  userNs.refer(Symbol.create(null, "cdoc"), var("cd-client.core", "cdoc"));
  this.ns.set(userNs);
}

代码示例来源:origin: videlalvaro/clochure

Class referenceClass(Symbol sym, Class val){
  if(sym.ns != null)
    {
    throw new IllegalArgumentException("Can't intern namespace-qualified symbol");
    }
  IPersistentMap map = getMappings();
  Class c = (Class) map.valAt(sym);
  while((c == null) || (areDifferentInstancesOfSameClassName(c, val)))
    {
    IPersistentMap newMap = map.assoc(sym, val);
    mappings.compareAndSet(map, newMap);
    map = getMappings();
    c = (Class) map.valAt(sym);
    }
  if(c == val)
    return c;

  throw new IllegalStateException(sym + " already refers to: " + c + " in namespace: " + name);
}

代码示例来源:origin: org.dunaj/clojure

var = currentNS().intern(name);
else
  var = ns.findInternedVar(name);
  Object o = currentNS().getMapping(sym);
  if(o == null)
      var = currentNS().intern(Symbol.intern(sym.name));

代码示例来源:origin: org.dunaj/clojure

public static Var find(Symbol nsQualifiedSym){
  if(nsQualifiedSym.ns == null)
    throw new IllegalArgumentException("Symbol must be namespace-qualified");
  Namespace ns = Namespace.find(Symbol.intern(nsQualifiedSym.ns));
  if(ns == null)
    throw new IllegalArgumentException("No such namespace: " + nsQualifiedSym.ns);
  return ns.findInternedVar(Symbol.intern(nsQualifiedSym.name));
}

代码示例来源:origin: org.dunaj/clojure

static public Object maybeResolveIn(Namespace n, Symbol sym) {
  //note - ns-qualified vars must already exist
  if(sym.ns != null)
    {
    Namespace ns = namespaceFor(n, sym);
    if(ns == null)
      return null;
    Var v = ns.findInternedVar(Symbol.intern(sym.name));
    if(v == null)
      return null;
    return v;
    }
  else if(sym.name.indexOf('.') > 0 && !sym.name.endsWith(".") 
      || sym.name.charAt(0) == '[')
    {
    return RT.classForName(sym.name);
    }
  else if(sym.equals(NS))
      return RT.NS_VAR;
    else if(sym.equals(IN_NS))
        return RT.IN_NS_VAR;
      else
        {
        Object o = n.getMapping(sym);
        return o;
        }
}

代码示例来源:origin: org.dunaj/clojure

public void removeAlias(Symbol alias) {
  IPersistentMap map = getAliases();
  while(map.containsKey(alias))
    {
    IPersistentMap newMap = map.without(alias);
    aliases.compareAndSet(map, newMap);
    map = getAliases();
    }
}

代码示例来源:origin: org.dunaj/clojure

static Namespace namespaceFor(Namespace inns, Symbol sym){
  //note, presumes non-nil sym.ns
  // first check against currentNS' aliases...
  Symbol nsSym = Symbol.intern(sym.ns);
  Namespace ns = inns.lookupAlias(nsSym);
  if(ns == null)
    {
    // ...otherwise check the Namespaces map.
    ns = Namespace.find(nsSym);
    }
  return ns;
}

代码示例来源:origin: videlalvaro/clochure

else
  Object o = currentNS().getMapping(sym);
  if(o instanceof Class)
    c = (Class) o;

代码示例来源:origin: videlalvaro/clochure

public void unmap(Symbol sym) {
  if(sym.ns != null)
    {
    throw new IllegalArgumentException("Can't unintern namespace-qualified symbol");
    }
  IPersistentMap map = getMappings();
  while(map.containsKey(sym))
    {
    IPersistentMap newMap = map.without(sym);
    mappings.compareAndSet(map, newMap);
    map = getMappings();
    }
}

代码示例来源:origin: videlalvaro/clochure

public static Namespace findOrCreate(Symbol name){
  Namespace ns = namespaces.get(name);
  if(ns != null)
    return ns;
  Namespace newns = new Namespace(name);
  ns = namespaces.putIfAbsent(name, newns);
  return ns == null ? newns : ns;
}

代码示例来源:origin: org.apache.nifi/nifi-scripting-processors

@Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
  try {
    // Get engine bindings and send them to Clojure
    Bindings engineBindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
    engineBindings.entrySet().forEach((entry) -> Var.intern(Namespace.findOrCreate(NAMESPACE_SYMBOL), Symbol.create(entry.getKey().intern()), entry.getValue(), true));
    Var.pushThreadBindings(
        RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref(),
            RT.IN, new LineNumberingPushbackReader(context.getReader()),
            RT.OUT, context.getWriter(),
            RT.ERR, context.getErrorWriter()));
    Object result = Compiler.load(reader);
    return result;
  } catch (Exception e) {
    throw new ScriptException(e);
  } finally {
    Namespace.remove(NAMESPACE_SYMBOL);
  }
}

代码示例来源:origin: videlalvaro/clochure

public static Var intern(Namespace ns, Symbol sym){
  return ns.intern(sym);
}

代码示例来源:origin: org.dunaj/clojure

Object reference(Symbol sym, Object val){
  if(sym.ns != null)
    {
    throw new IllegalArgumentException("Can't intern namespace-qualified symbol");
    }
  IPersistentMap map = getMappings();
  Object o;
  while((o = map.valAt(sym)) == null)
    {
    IPersistentMap newMap = map.assoc(sym, val);
    mappings.compareAndSet(map, newMap);
    map = getMappings();
    }
  if(o == val)
    return o;

  warnOrFailOnReplace(sym, o, val);

  while(!mappings.compareAndSet(map, map.assoc(sym, val)))
    map = getMappings();

  return val;

}

代码示例来源:origin: org.dunaj/clojure

Class referenceClass(Symbol sym, Class val){
  if(sym.ns != null)
    {
    throw new IllegalArgumentException("Can't intern namespace-qualified symbol");
    }
  IPersistentMap map = getMappings();
  Class c = (Class) map.valAt(sym);
  while((c == null) || (areDifferentInstancesOfSameClassName(c, val)))
    {
    IPersistentMap newMap = map.assoc(sym, val);
    mappings.compareAndSet(map, newMap);
    map = getMappings();
    c = (Class) map.valAt(sym);
    }
  if(c == val)
    return c;

  throw new IllegalStateException(sym + " already refers to: " + c + " in namespace: " + name);
}

相关文章