Package clojure.lang

Examples of clojure.lang.Var


    @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));
            } else {
                return DiametricUtils.convertJavaToRuby(context, var.invoke(set, other));
            }
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here


        }
    }

    private int getCount() {
        if (count == null) {
            Var var = DiametricService.getFn("clojure.core", "count");
            count = (Integer)var.invoke(set);
        }
        return count;
    }
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));
            } else {
                return DiametricSet.getDiametricSet(context, (Set)var.invoke(set, other));
            }
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
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));
            } else {
                return DiametricSet.getDiametricSet(context, (Set)var.invoke(set, other));
            }
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here

    @JRubyMethod(meta=true)
    public static IRubyObject be_lazy(ThreadContext context, IRubyObject klazz, IRubyObject arg) {
        try {
            clojure.lang.PersistentVector v =
                    (clojure.lang.PersistentVector)arg.toJava(clojure.lang.PersistentVector.class);
            Var var = DiametricService.getFn("clojure.core", "take");
            Object value = var.invoke(100, v);
            return DiametricCollection.getDiametricCollection(context, (List)value);
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here

        if (!(arg instanceof List)) {
            throw context.getRuntime().newRuntimeError("argument should be array");
        }
        List other = (List)arg;
        try {
            Var two_arrays_diff_fn = null;
            if (DiametricService.fnMap.containsKey("two-arrays-diff")) {
                two_arrays_diff_fn = DiametricService.fnMap.get("two-arrays-diff");
            } else {
                Var var = DiametricService.getFn("clojure.core", "load-string");
                String fn =
                        "(defn two-arrays-diff [this other]\n" +
                        "  (let [f (fn [ary n] (remove (partial = n) ary))]\n"+
                        "    (reduce f this other)))";
                two_arrays_diff_fn = (Var)var.invoke(fn);
                DiametricService.fnMap.put("two-arrays-diff", two_arrays_diff_fn);
            }
            Object value = two_arrays_diff_fn.invoke(vector_or_seq, other);
            return DiametricCollection.getDiametricCollection(context, (List)value);
        } catch (Throwable t) {
View Full Code Here

    @JRubyMethod(name="*")
    public IRubyObject op_times(ThreadContext context, IRubyObject arg) {
        if (arg instanceof RubyFixnum) {
            try {
                Var append_n_times_fn = null;
                if (DiametricService.fnMap.containsKey("append-n-times")) {
                    append_n_times_fn = DiametricService.fnMap.get("append-n-times");
                } else {
                    Var var = DiametricService.getFn("clojure.core", "load-string");
                    append_n_times_fn = (Var)var.invoke("(defn append-n-times [n array] (reduce concat (replicate n array)))");
                    DiametricService.fnMap.put("append-n-times", append_n_times_fn);
                }
                Integer n = (Integer)arg.toJava(Integer.class);
                Object value = append_n_times_fn.invoke(n, vector_or_seq);
                return DiametricCollection.getDiametricCollection(context, (List)value);
View Full Code Here

        if (!(arg instanceof List)) {
            throw context.getRuntime().newRuntimeError("argument should be array");
        }
        List other = (List)arg;
        try {
            Var var = DiametricService.getFn("clojure.core", "concat");
            Object value = var.invoke(vector_or_seq, other);
            return DiametricCollection.getDiametricCollection(context, (List)value);
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here

    @JRubyMethod(name="<=>")
    public IRubyObject op_cmp(ThreadContext context, IRubyObject arg) {
        if (!(arg instanceof List)) return context.getRuntime().getNil();
        List other = (List)arg;
        try {
            Var var = DiametricService.getFn("clojure.core", "compare");
            Integer value = (Integer)var.invoke(vector_or_seq, other);
            return context.getRuntime().newFixnum(value);
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError(t.getMessage());
        }
    }
View Full Code Here

        }
    }

    private IRubyObject commonArefIndex(ThreadContext context, Long index) {
        try {
            Var var = DiametricService.getFn("clojure.core", "nth");
            Object value = var.invoke(vector_or_seq, index);
            return DiametricUtils.convertJavaToRuby(context, value);
        } catch (Throwable t) {
            if (t instanceof IndexOutOfBoundsException) {
                // raised only from [index] when index is greater than the last index or negative
                if (index >= (long)getCount()) return context.getRuntime().getNil();
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.