View clj-1.8.0-alpha2-tuple-perf.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; *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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ======================================================================= | |
;; 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 )) |
View Test Clojure Code.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def test-map | |
{:a 1 :b 2}) |