Skip to content

Instantly share code, notes, and snippets.

=> ((proxy [clojure.lang.RestFn] []
(getRequiredArity [] 2)
(doInvoke [a b rest]
(println a b rest))))
#<ArityException clojure.lang.ArityException: Wrong number of args (0) passed to: RestFn$0>
=> ((proxy [clojure.lang.RestFn] []
(getRequiredArity [] 2)
(doInvoke [a b rest]
(println a b rest))) 4 5)
4 5 nil
; A solution to https://4clojure.com/problem/102 that doesn't involve cl-format
#(clojure.string/replace % #"-." (fn [m] (-> m last Character/toUpperCase str)))
+------------------+
| |
| |
+--------------------------+ Client |
| Data in (PUT) | |
| | |
| | |
| +------------------+
| + ^
=> (defmacro apply.
[method-name & object+args]
`(~method-name ~@(flatten object+args)))
#'user/apply.
=> (apply. .substring "foobar" [0 4])
"foob"
; above works only at compile time, so won't work with seqs of undetermined length at runtime. A sane place to use eval:
;; no exception when declare/defn are top-level (unsurprisingly)
=> (list
(declare ^:dynamic p)
(defn q [] @p))
(#'user/p #'user/q)
=> (binding [p (atom 10)]
(q))
#<ClassCastException java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to clojure.lang.IDeref>
@cemerick
cemerick / gist:1312660
Created October 25, 2011 13:06
^:const example
=> (def ^:const a 5)
#'user/a
=> (defn b [] a)
#'user/b
=> (def a 10)
#'user/a
=> (b)
5
@cemerick
cemerick / gist:1452640
Created December 9, 2011 18:05
dependency-tree for Leiningen
;; requires [com.cemerick/pomegranate "0.0.2"]
;; i.e. https://github.com/cemerick/pomegranate
(use '[cemerick.pomegranate.aether :only (dependency-hierarchy resolve-dependencies)])
=> (pprint
(dependency-hierarchy
'[[incanter "1.2.3"]]
(resolve-dependencies {:coordinates '[[incanter "1.2.3"]]
:repositories (merge cemerick.pomegranate.aether/maven-central {"clojars" "http://clojars.org/repo"})})))
@cemerick
cemerick / gist:1485920
Created December 16, 2011 12:46
Working on a CouchDB type for Clojure
;; Clutch provides a pretty comprehensive API, but I'm frustated that 95% of database
;; interactions require using something other than the typical Clojure vocabulary of
;; assoc/conj/dissoc/get/seq/reduce/etc, even though those semantics are entirely appropriate
;; (modulo the whole stateful database thing).
;;
;; This is (the start of) an attempt to create a type to provide most of the
;; functionality of Clutch with a more pleasant, concise API (it uses the Clutch API
;; under the covers, and rare operations would generally remain accessible only
;; at that lower level).
;;
@cemerick
cemerick / gist:1616042
Created January 15, 2012 14:38
compiling Clojure before Java sources
;; Example from _Clojure Programming_; exposition on it, Leiningen, hooks,
;; and compilation order found therein. http://www.clojurebook.com
(defproject com.clojurebook/lein-mixed-source "1.0.0"
:dependencies [[org.clojure/clojure "1.3.0"]]
:aot :all)
(require '(leiningen compile javac))
(add-hook #'leiningen.compile/compile
@cemerick
cemerick / gist:1875896
Created February 21, 2012 11:09
gitx gh-153: Crash attempting to move a branch by dragging its label in the tree UI
Process: GitX [5035]
Path: /Applications/GitX.app/Contents/MacOS/GitX
Identifier: nl.frim.GitX
Version: 0.8.4 (0.8.4)
Code Type: X86-64 (Native)
Parent Process: launchd [328]
Date/Time: 2012-02-21 06:05:39.422 -0500
OS Version: Mac OS X 10.7.3 (11D50b)
Report Version: 9