Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
;; Inspired by George Jahad's version: http://georgejahad.com/clojure/debug-repl.html | |
(defmacro local-bindings | |
"Produces a map of the names of local bindings to their values." | |
[] | |
(let [symbols (map key @clojure.lang.Compiler/LOCAL_ENV)] | |
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols))) | |
(declare *locals*) | |
(defn eval-with-locals |
(require '[clojure.core.async :as a]) | |
(def xform (comp (map inc) | |
(filter even?) | |
(dedupe) | |
(flatmap range) | |
(partition-all 3) | |
(partition-by #(< (apply + %) 7)) | |
(flatmap flatten) | |
(random-sample 1.0) |
Function.prototype.bind = (function(origBind) { | |
return function() { | |
var fn = origBind.apply(this, arguments); | |
fn.__origFn__ = this.__origFn__ || this; | |
return fn; | |
}; | |
}(Function.prototype.bind)); | |
Function.prototype.unbind = function() { | |
return this.__origFn__; |
I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.
This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea
Inspired by https://github.com/slipset/friendly
I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202
Usage:
clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "9bd01f28522a0083c6a7428a871aa5fbb8070d1d"}}}' -m friendly
Inspired by https://github.com/slipset/friendly
I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202
Usage:
clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "9bd01f28522a0083c6a7428a871aa5fbb8070d1d"}}}' -m friendly
iTerm2 emacs 24.2.1 -nw with paredit on OS X 10.8 Norwegian layout | |
Left Command is my Meta. | |
Left Alt used for inputting special characters. | |
Caps Lock is mapped to Control. | |
> System Preferences > Keyboard > Keyboard > Special: Caps Lock: ^ Control | |
iTerm > Preferences > Keys: Left Command key mapped to Right Option | |
iTerm > Preferences > Profiles > Keys: Right option acts as: +Esc |
;; REPL ONLY | |
;; Require clj-http https://github.com/dakrone/clj-http/ | |
(require '[clj-http.client :as client]) | |
;; Import Apache Common's Base64 encoder/decoder | |
(import (org.apache.commons.codec.binary Base64)) | |
(def test-file | |
;Image Credit Metropolitan Museum of Art | |
(client/get "http://images.metmuseum.org/CRDImages/ma/web-large/DP241865.jpg" {:as :byte-array})) |
First, you need to install GraalVM and set things up so that the java
installed with GraalVM is picked up in your path.
See http://www.graalvm.org for more details.
With that in place, you can manage the Truffle languages installed.
Here you can see that I've already installed Python and Ruby:
$ gu list
ComponentId Version Component name