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
{"nodes":[ | |
{"x":80, "r":40, "label":"Node 1"}, | |
{"x":200, "r":60, "label":"Node 2"}, | |
{"x":380, "r":80, "label":"Node 3"} | |
]} |
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
// After reading the trials and tribulations here | |
// http://www.learningclojure.com/2014/05/fizz-buzz-interview-question.html?utm_source=dlvr.it&utm_medium=twitter | |
// I decided to see how easy this is using sum types. | |
// Anser: Pretty easy. :D | |
object Program { | |
def numbers(n: Int): Stream[Int] = Stream.cons(n, numbers(n + 1)) | |
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 baseball.core | |
(:require [clojure.core.async :refer (chan >!! <!! >! <! close! go go-loop)] | |
[clojure.core.match :refer (match)])) | |
;; http://www.variousandsundry.com/cs/blog/2014/02/20/baseball-processes/ | |
;; It’s like playing catch in the backyard. You don’t want to play by yourself. So you tell a friend | |
;; to stand about 20 paces away from you. Once they’re there, they wave their arms to be sure you can | |
;; see them. Having seen them, you throw them the ball. They throw it back as a solid line drive | |
;; right at your mitt. End of process. |
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
abstract class Show<A> { | |
public static register(Class c, Show s){ | |
Map<Class,Object> shows=TypeClassFactory.tcs.get(Show.class) | |
if(shows!=null){ | |
shows.put(c,s); | |
}else{ | |
shows = new Map<Class,Object>(); | |
shows.put(c,s); | |
TypeClassFactory.tcs.put(Show.class, shows); |
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
;; The macros | |
;; most macros here alias names from select.cljs | |
;; they will get used in regular calls | |
(ns lib.select | |
(:require | |
[clojure.string :as str])) | |
;; selector syntax | |
(defn intersection [preds] |
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 workbench.enlive.predicate | |
(:require | |
[clojure.zip :as z] | |
[workbench.enlive.engine | |
:refer [compile-step]] | |
[workbench.enlive.select | |
:refer [zip-select]])) | |
;; ## Builtin predicates | |
;; |
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 lambda-calc.core) | |
;; THIS MACRO CREATES A LAMBDA THAT IS COMPATABLE WITH LAMBDA AS DEFINED IN | |
;; LAMBDA CALCULUS -> CURRIED NON-RECURSIVE | |
(defmacro f* [args & body] | |
(let [fsym (gensym "fn") | |
alist (for [n (range 1 (count args))] | |
(take n args)) | |
curries (map #(do `(~(vec %) (partial ~fsym ~@%))) alist)] | |
`(fn ~fsym ~@curries (~args ~@body)))) |
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
The Objective | |
This language experiment was designed to show how parametric polymorphism and type classes are | |
implemented in different languages. The implementation languages where chosen out of personal | |
preference. I am well aware it's not complete and would love for you to help me with that. If | |
you don't see your favorite language please add it as a comment. I am also not an expert in all | |
of these languages but did try to make them as idiomatic as possible. If you believe there is a | |
better solution please leave a comment with the implementation. | |
The Code |
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 & [f k] | |
(fn [& args] | |
(k (apply f args)))) | |
(defmacro cps [steps] | |
(if (seq steps) | |
`(& ~(first steps) | |
(cps ~(rest steps))) | |
`identity)) |
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
object P26 extends App { | |
def combinations[T](n: Int, l: List[T]): List[List[T]] = { | |
if(l.size < n) { | |
Nil | |
} else { | |
n match { | |
case 0 => Nil | |
case 1 => l.map{List(_)} | |
case _ => combinations(n-1,l.tail).map{ l.head :: _} ::: combinations(n, l.tail) | |
} |
NewerOlder