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
;; A sketch of Clojure-like protocols, implemented in Mal | |
;; Mal is https://github.com/kanaka/mal | |
(def! builtin-type (fn* [obj] | |
(cond | |
(list? obj) :mal/list | |
(vector? obj) :mal/vector | |
(map? obj) :mal/map | |
(symbol? obj) :mal/symbol | |
(keyword? obj) :mal/keyword |
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
package mypkg; | |
public class Ugly { | |
public Ugly(){} | |
public String foo(boolean i) { return "bool: " + i; } | |
public String foo(Object o) { return "obj: " + o; } | |
} |
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
(ns us.chouser.malli-play | |
(:require [malli.core :as m] | |
[malli.error :as me]) | |
(:import (clojure.lang ExceptionInfo))) | |
;; {:deps {metosin/malli {:mvn/version "0.10.1"}}} | |
;; No refinement chaining yet | |
;; No clear separation of constraint violation from runtime error | |
(defn var-sym [v] |
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
;; primitive lazy-seq | |
(defn filter-with-context-ls [pred n coll] | |
(let [step (fn step [buffer suffix coll] | |
(lazy-seq | |
(when-let [[v & more] (seq coll)] | |
(if (pred v) | |
(concat (take-last n buffer) [v] (step [] n more)) | |
(if (pos? suffix) | |
(cons v (step [] (dec suffix) more)) | |
(step (conj buffer v) 0 more))))))] |
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
(ns us.chouser.merge-sort | |
"Experiments in parallel folding of vectors" | |
(:require [clojure.core.reducers :as r] | |
[criterium.core :as c] | |
[dom-top.core :refer [loopr]])) | |
(set! *warn-on-reflection* true) | |
(defn array-type | |
"Return a string representing the type of an array with dims |
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
(ns io.chouser.experiment | |
(:require [clojure.core.async :as async])) | |
(defn bang [] | |
(future | |
(dotimes [i 10] | |
(async/go | |
(print (str "start " i "\n")) (flush) | |
(Thread/sleep 20000) | |
(prn :done i))))) |
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
; STM history stress-test | |
(defn stress [hmin hmax] | |
(let [r (ref 0 :min-history hmin :max-history hmax) | |
slow-tries (atom 0)] | |
(future | |
(dosync | |
(swap! slow-tries inc) | |
(Thread/sleep 200) | |
@r) |
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
// This is the map function to give to CouchDB: | |
function(doc) { | |
function xemit(key, val) { | |
emit(key, {key: key, val: val}); | |
} | |
// Your code goes here, working with the doc provided. | |
// Use xemit(key, value) instead of CouchDB's emit | |
// ... |
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
(defn array-type | |
"Return a string representing the type of an array with dims | |
dimentions and an element of type klass. | |
For primitives, use a klass like Integer/TYPE | |
Useful for type hints of the form: ^#=(array-type String) my-str-array" | |
([klass] (array-type klass 1)) | |
([klass dims] | |
(.getName (class | |
(apply make-array | |
(if (symbol? klass) (eval klass) klass) |
NewerOlder