Skip to content

Instantly share code, notes, and snippets.

(defn ^:static fib ^long [^long n]
(if (>= (long 1) n)
(long 1)
(+ (fib (dec n)) (fib (- n (long 2))))))
(dotimes [_ 10] (time (fib 38)))
[java] FAIL in (test-annotations) (test_clojure.clj:92)
[java] Parameter annotations: void foo(@Retention(?) String)
[java] expected: (instance? Retention retention)
[java] actual: $Proxy2
[java]
[java] FAIL in (test-annotations) (test_clojure.clj:92)
[java] Parameter annotations: void foo(@Target(?) String)
[java] expected: (instance? Target target)
[java] actual: $Proxy1
[java]
(definterface ITak
(#^int tak [#^int x #^int y #^int z]))
(deftype Tak []
ITak
(tak [this x y z]
(if (>= y x)
z
(recur (.tak this (dec x) y z)
(.tak this (dec y) z x)
;sample use idea:
(defn mapx
"Returns a lazy sequence consisting of the result of applying f to the
set of first items of each coll, followed by applying f to the set
of second items in each coll, until any one of the colls is
exhausted. Any remaining items in other colls are ignored. Function
f should accept number-of-colls arguments."
[f coll]
(gen-iter iter [f seq-cell]
(defmacro gen-iter-fn
[name [op coll] has-item-body item-body move!-body]
`(defn ~name [~op ~coll]
(letfn
[(iter# [~op ~coll]
(reify :as ~'this
~'Iter
(~'has-item [] ~@has-item-body)
(~'item [] ~@item-body)
(~'move! [] ~@move!-body)
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
(reify
[ActionListener
(actionPerformed [this evt] ...)])
(deftype ::MyType [a b c]
[SeqableProtocol
(seq-me [this] (blah a c))]
[IBarInterface
(.bar [this that] (fred b))])