This file contains hidden or 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 comp+ | |
([] identity) | |
([f] f) | |
([f g] | |
(fn | |
([] (f (g))) | |
([x] (f (g x))) | |
([x y] (f (g x y))) | |
([x y z] (f (g x y z))) |
This file contains hidden or 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 comp+ | |
([] identity) | |
([f] f) | |
([f g] | |
(fn | |
([] (f (g))) | |
([x] (f (g x))) | |
([x y] (f (g x y))) | |
([x y z] (f (g x y z))) |
This file contains hidden or 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 comp+ | |
([] identity) | |
([f] f) | |
([f g] | |
(fn | |
([] (f (g))) | |
([x] (f (g x))) | |
([x y] (f (g x y))) | |
([x y z] (f (g x y z))) |
This file contains hidden or 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 sqr #(*% %)) | |
(def csqr (with-constraints sqr | |
(contract number-cnstr | |
"constrains the act of squaring" | |
[n] number? (not= 0 n) => number? pos?)) | |
(csqr 10) | |
;=> 100 |
This file contains hidden or 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
;; returns a map | |
(def numbered-elements (partial zipmap (iterate inc 0))) | |
(numbered-elements '[a b c d]) | |
;=> {3 d, 2 c, 1 b, 0 a} | |
;; returns a seq of pairs | |
(def numbered-elements #(->> % (interleave (iterate inc 0)) (partition 2))) | |
(numbered-elements '[a b c d]) |
This file contains hidden or 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 mvec #(vec (map % %&))) | |
(mvec #(* % %) 1 2 3 4 5) | |
(mvec #(.toUpperCase %) "test") | |
;; The original doesn't return vectors -- it returns lazy seqs |
This file contains hidden or 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 fogus | |
(:refer-clojure :exclude [or +])) | |
(defprotocol ReadOps | |
(+ [this rhs]) | |
(or [this rhs])) | |
(extend-type String | |
ReadOps | |
(+ [this rhs] |
This file contains hidden or 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 sqr-8bit-contract | |
(contract atari-constraints | |
"Defines the constraints for Atari 2600 squaring" | |
[n] [(< n 16) integer? pos? => (< % 256)])) | |
(def sqr-8bit | |
(with-constraints | |
constrained-sqr | |
sqr-8bit-contract)) |
This file contains hidden or 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
#include "stdio.h" | |
#include "stdlib.h" | |
#include "string.h" | |
typedef char C;typedef long I; | |
typedef struct a{I t,r,d[3],p[2];}*A; | |
#define P printf | |
#define R return | |
#define V1(f) A f(w)A w; | |
#define V2(f) A f(a,w)A a,w; |
This file contains hidden or 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
(defmacro defunits-of [quantity base-unit & units] | |
(let [magnitude (gensym) | |
unit (gensym) | |
conversions (apply hash-map base-unit 1 units)] | |
`(defmacro ~(symbol (str "unit-of-" quantity)) | |
[~magnitude ~unit] | |
`(* ~~magnitude | |
~(relative-units ~unit ~conversions))))) |