Package clojure.lang

Examples of clojure.lang.Var


public final class ClojureUtils {
  private static ConcurrentHashMap<String, Var> cachedVars = new ConcurrentHashMap<String, Var>();
 
  private static Var var(String ns, String name) {
    String varName = ns + "/" + name;
    Var v = cachedVars.get(varName);
    if (v != null) {
      return v;
    } else {
      v = RT.var(ns, name);
      if (v == null) {
View Full Code Here


      final IEclipseContext context) {
    CCWPlugin.getTracer().trace(TraceOptions.LOG_INFO, "create object for bundleclass://" + bundle.getSymbolicName() + "/" + "clojure" + "/" + varAndParams);
    try {
      final String[] parts = varAndParams.split("\\/");
      String var = parts[0] + "/" + parts[1];
      final Var v = BundleUtils.requireAndGetVar(bundle, var);
      return ClojureOSGi.withBundle(bundle, new RunnableWithException() {
        @Override
        public Object run() throws Exception {
          switch (parts.length) {
          case 2: return v.invoke(context);
          case 3: return v.invoke(context, parts[2]);
          case 4: return v.invoke(context, parts[2], parts[3]);
          case 5: return v.invoke(context, parts[2], parts[3], parts[4]);
          case 6: return v.invoke(context, parts[2], parts[3], parts[4], parts[5]);
          case 7: return v.invoke(context, parts[2], parts[3], parts[4], parts[5], parts[6]);
          case 8: return v.invoke(context, parts[2], parts[3], parts[4], parts[5], parts[6], parts[7]);
          default: throw new UnsupportedOperationException("Cannot handle more than 6 arguments");
          }
        }
      });
    } catch (CoreException e) {
View Full Code Here

 
  private final static Pattern SEARCH_DECLARING_NAMESPACE_PATTERN
    = Pattern.compile("\\(\\s*(?:in-)?ns\\s+([^\\s\\)#\\[\\'\\{]+)");

  public static String findDeclaringNamespace(String sourceText) {
    Var sexp = RT.var("paredit.parser", "sexp");
    try {
      return (String) findDeclaringNamespace((Map) sexp.invoke(sourceText));
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

* @author Sam
*/
public class ClojureConsole {
    public static void main(String[] args) {
        Symbol CLOJURE_MAIN = Symbol.intern("clojure.main");
        Var REQUIRE = RT.var("clojure.core", "require");
        Var MAIN = RT.var("clojure.main", "main");
        try {
            REQUIRE.invoke(CLOJURE_MAIN);
            MAIN.applyTo(RT.seq(new String[]{}));
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

          try {
              // Load the Clojure script -- as a side effect this initializes the runtime.
              RT.loadResourceScript(getClojureGamerFile() + ".clj");

              // Get a reference to the gamer-generating function.
              Var gamerVar = RT.var("gamer_namespace", getClojureGamerName());

              // Call it!
              theClojureGamer = (Gamer)gamerVar.invoke();
          } catch(Exception e) {
              GamerLogger.logError("GamePlayer", "Caught exception in Clojure initialization:");
              GamerLogger.logStackTrace("GamePlayer", e);
          }
      }
View Full Code Here

    _name = name;
    this.hofArgs = hofArgs;
  }

  public Object toVar() {
    Var ret = Util.getVar(_namespace, _name);
    if (!hofArgs.isEmpty())
      return ret.applyTo(Util.coerceToSeq(hofArgs));
    else
      return ret.deref();
  }
View Full Code Here

  public static List INTEGER = getDataset("integer");
  public static List SENTENCE = getDataset("sentence");


  private static List getDataset(String name) {
    Var v = Util.getVar("cascalog.playground", name);
    return (List) v.deref();
  }
View Full Code Here

        //RT.loadResourceScript("foo.clj");
        Compiler.load(new StringReader(str));

        // Get a reference to the foo function.
        Var foo = RT.var("user", "foo");
        Var a = RT.var("user", "a"); // reference to the variable a

        // Call it!
        Object result = foo.invoke("Hi", "there");
        System.out.println(result);
       
        System.out.println(a);
        System.out.println(a.get());
    }
View Full Code Here

      final Set<Entry<String, Object>> entrySet = bindings.entrySet();
      for (final Entry<String, Object> entry : entrySet)
      {
        final Symbol symbol = Symbol.intern(entry.getKey());
        final Namespace userNs = Namespace.findOrCreate(Symbol.create("user".intern()));
        final Var var = Var.intern(userNs, symbol);
        var.setDynamic(true);
        mappings = mappings.assoc(var, entry.getValue());
      }
    }
    return mappings;
  }
View Full Code Here

public class main
{
  public static void main(String[] args) throws Exception
  {
    RT.loadResourceScript("speclj/main.clj");
    Var main = RT.var("speclj.main", "-main");
    Var apply = RT.var("clojure.core", "apply");
    apply.invoke(main, args);
  }
View Full Code Here

TOP

Related Classes of clojure.lang.Var

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.