View clj-1.8.0-alpha2-tuple-perf.clj
;; *clojure-version*
;; (require '[taoensso.encore :as encore])
(let [v [1 2 3 4]
x 1
y 2
z 3]
(encore/qbench ; Returns fastest of 3 sets of lap times for each form, in msecs
1000000 ; Number of laps
View gist:8bcbf0e037df312c6bf6
;; Using criterium to test performance of Tuples
;;
;; Benchmark using parts of the core.matrix implementation test suite
;;
;; ===========================================================
;; Common setup:
(use '[criterium.core :as c])
(require 'clojure.core.matrix.compliance-tester)
View gist:2a3ed082b07a4f65cbcc
;; =======================================================================
;; Motivation: we are interested in the performance of tiny
;; wrapper functions which look like:
;; (fn [_ x y] (g x y))
;;
;; Question: are they getting the full performance benefits of inlining?
(ns test
(:require [criterium.core :as c]))
View clojure-match.clj
(use '[clojure.core.match :only [match]])
(defn evaluate [env [sym x y]]
(match [sym]
['Number] x
['Add] (+ (evaluate env x) (evaluate env y))
['Multiply] (* (evaluate env x) (evaluate env y))
['Variable] (env x)))
(def environment {"a" 3, "b" 4, "c" 5})
View gist:1332788
(sample-normal 5)
=> (-0.10224658005696823 -0.39374760130345093 -0.9347003327466611 0.027885002566669224 -0.5329681018922551)
(view (histogram (sample-normal 1000)))
(view (function-plot sin -10 10))
View gist:1332761
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Frequency analysis (implicitly treating a string as a sequence of chars)
(frequencies "abracadabra")
=> {\a 5, \b 2, \r 2, \c 1, \d 1}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Infinite, lazily calculated sequence of Fibonacci numbers
View enodyt-4clojure-solution94.clj
;; enodyt's solution to Game of Life
;; https://4clojure.com/problem/94
(fn [board]
(let [dx (count (first board))
dy (count board)
neighbours (fn [pos board]
(let [xs [[-1 -1] [0 -1] [1 -1]
[-1 0] [1 0]
[-1 1] [0 1] [1 1]]]
View gist:1104578
;; Objective
;; 1. Learn Clojure by doing Clojure
;;
;; Pre-requisites
;; You need to have a running Clojure REPL
;; see: http://clojure.org/getting_started
; Hello World in Clojure
(println "Hello World")
View gist:970439
;; event application with subsequent events
;; event :: state -> (state' [event])
(defn update-with-events [state events]
(if-let [event (first events)]
(let [other-events (rest events)
[updated-state new-events] (event game)]
(recur updated-state (concat other-events new-events)))
state ))