Package clojure.lang

Examples of clojure.lang.Var


            throw context.getRuntime().newArgumentError("Argument should be a Fixnum");
        }
        if (vector_or_seq.isEmpty()) return context.getRuntime().newEmptyArray();
        Long n = (Long)arg.toJava(Long.class);
        try {
            Var var = DiametricService.getFn("clojure.core", "take-last");
            return DiametricUtils.convertJavaToRuby(context, var.invoke(n, vector_or_seq));
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here


        throw context.getRuntime().newRuntimeError("Not yet supported. Might be implented later depends on datomic queries.");
    }

    private int getCount() {
        if (count == null) {
            Var var = DiametricService.getFn("clojure.core", "count");
            count = (Integer)var.invoke(vector_or_seq);
        }
        return count;
    }
View Full Code Here

        RubyHash params = (RubyHash)args[0];
        if (params.size() < 3) {
            throw context.getRuntime().newArgumentError("This method needs at least :lang, :params, and :code keys with values");
        }
        try {
            Var hash_map_fn = DiametricService.getFn("clojure.core", "hash-map");
            clojure.lang.PersistentArrayMap clj_map =
                    (PersistentArrayMap) hash_map_fn.invoke();
            Var assoc_fn = DiametricService.getFn("clojure.core", "assoc");
            String[] keys = new String[] { "lang", "params", "code", "requires", "imports" };
            Class[] valueTypes =
                    new Class[] { RubySymbol.class, RubyArray.class, RubyString.class, RubyArray.class, RubyArray.class };
            for (int i = 0; i < keys.length; i++) {
                RubySymbol ruby_key = context.getRuntime().newSymbol(keys[i]);
                IRubyObject ruby_value = params.op_aref(context, ruby_key);
                if (ruby_value.isNil()) continue;
                clj_map = (PersistentArrayMap) assoc_fn.invoke(
                            clj_map,
                            DiametricService.keywords.get(ruby_key.toString()),
                            convertRubyValueToJava(context, ruby_value, valueTypes[i]));
            }
            RubyClass clazz = (RubyClass) context.getRuntime().getClassFromPath("Diametric::Persistence::Function");
            DiametricFunction ruby_function = (DiametricFunction) clazz.allocate();
            Var function_fn = DiametricService.getFn("datomic.api", "function");
            ruby_function.init((datomic.function.Function) function_fn.invoke(clj_map));
            return ruby_function;
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here

        }
    }

    private static List convertArrayElementsToJava(ThreadContext context, RubyArray ruby_array) {
        List list = new ArrayList<clojure.lang.Symbol>();
        Var symbol_fn = DiametricService.getFn("clojure.core", "symbol");
        for (int i=0; i<ruby_array.size(); i++) {
            IRubyObject element = ruby_array.at(context.getRuntime().newFixnum(i));
            if (element instanceof RubySymbol) { // params
                list.add(symbol_fn.invoke(((RubySymbol)element).toString()));
            } else if (element instanceof RubyString) { // requires and imports
                list.add(((RubyString)element).asJavaString());
            }
        }
        return list;
View Full Code Here

        return ary;
    }

    IRubyObject count(ThreadContext context, IRubyObject arg, Object target) {
        try {
            Var count_value_fn = null;
            if (DiametricService.fnMap.containsKey("count-value")) {
                count_value_fn = DiametricService.fnMap.get("count-value");
            } else {
                Var var = DiametricService.getFn("clojure.core", "load-string");
                count_value_fn = (Var)var.invoke("(defn count-value [v array] (count (filterv (partial = v) array)))");
                DiametricService.fnMap.put("count-value", count_value_fn);
            }
            Object value = DiametricUtils.convertRubyToJava(context, arg);
            return context.getRuntime().newFixnum((Integer)count_value_fn.invoke(value, target));
        } catch (Throwable t) {
View Full Code Here

        return context.getRuntime().newFixnum(count);
    }

    IRubyObject empty_p(ThreadContext context, Object target) {
        try {
            Var var = DiametricService.getFn("clojure.core", "empty?");
            if ((Boolean)var.invoke(target)) {
                return context.getRuntime().getTrue();
            } else {
                return context.getRuntime().getFalse();
            }
        } catch (Throwable t) {
View Full Code Here

        }
    }

    IRubyObject drop_or_take(ThreadContext context, Long n, Object target) {
        try {
            Var drop_or_take_fn = null;
            if (DiametricService.fnMap.containsKey("drop-or-take")) {
                drop_or_take_fn = DiametricService.fnMap.get("drop-or-take");
            } else {
                Var var = DiametricService.getFn("clojure.core", "load-string");
                drop_or_take_fn = (Var)var.invoke("(defn drop-or-take [n target] (apply vector (drop n target)))");
                DiametricService.fnMap.put("drop-or-take", drop_or_take_fn);
            }
            PersistentVector value = (PersistentVector)drop_or_take_fn.invoke(n, target);
            RubyClass clazz = (RubyClass) context.getRuntime().getClassFromPath("Diametric::Persistence::Collection");
            DiametricCollection ruby_collection = (DiametricCollection)clazz.allocate();
View Full Code Here

        }
    }

    IRubyObject first(ThreadContext context, Object target) {
        try {
            Var var = DiametricService.getFn("clojure.core", "first");
            return DiametricUtils.convertJavaToRuby(context, var.invoke(target));
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here

        }
    }
   
    IRubyObject first(ThreadContext context, Long n, Object target) {
        try {
            Var first_n_fn = null;
            if (DiametricService.fnMap.containsKey("first-n")) {
                first_n_fn = DiametricService.fnMap.get("first-n");
            } else {
                Var var = DiametricService.getFn("clojure.core", "load-string");
                first_n_fn = (Var)var.invoke("(defn first-n [n target] (apply vector (take n target)))");
                DiametricService.fnMap.put("first-n", first_n_fn);
            }
            PersistentVector value = (PersistentVector)first_n_fn.invoke(n, target);
            RubyClass clazz = (RubyClass) context.getRuntime().getClassFromPath("Diametric::Persistence::Collection");
            DiametricCollection ruby_collection = (DiametricCollection)clazz.allocate();
View Full Code Here

        }
    }
   
    IRubyObject hash(ThreadContext context, Object target) {
        try {
            Var var = DiametricService.getFn("clojure.core", "hash");
            Integer hash_value = (Integer)var.invoke(target);
            return context.getRuntime().newFixnum(hash_value);
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
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.