Keybase proof
I hereby claim:
- I am chouser on github.
- I am chouser (https://keybase.io/chouser) on keybase.
- I have a public key whose fingerprint is 2835 9367 72DD 2F1C BBCF BBED 94AE 902B F718 ED2A
To claim this, I am signing this object:
; In England the currency is made up of pound, £, and pence, p, and | |
; there are eight coins in general circulation: | |
; | |
; 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). | |
; | |
; It is possible to make £2 in the following way: | |
; | |
; 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p | |
; | |
; How many different ways can £2 be made using any number of coins? |
(ns party.units | |
(:refer-clojure :exclude [+ - * /]) | |
(:require [clojure.algo.generic.arithmetic :as ari :use [+ - * /]] | |
[clojure.algo.generic.math-functions :refer [pow]] | |
[clojure.repl :refer [doc source apropos dir find-doc]])) | |
(defrecord Measurement [sym factor units] | |
clojure.lang.IFn | |
(invoke [a b] (* a b))) |
I hereby claim:
To claim this, I am signing this object:
(require '[clojure.spec :as spec] | |
'[clojure.walk :refer [prewalk]]) | |
;; == Attempt 1 | |
;; Unfortunately entagled with 'reduce': | |
(defmacro reduce-query [& args] | |
(let [m (spec/conform | |
(spec/cat :q (spec/spec | |
(spec/cat :q #(= :q %) |
(require '[clojure.reflect :as r]) | |
(defn arg-counts [f] | |
(let [mems (:members (r/reflect f))] | |
{:args (set (map #(count (:parameter-types %)) | |
(filter #(= 'invoke (:name %)) mems))) | |
:varargs-ge (some #(when (= 'doInvoke (:name %)) | |
(dec (count (:parameter-types %)))) | |
mems)})) |
(ns n01se.citystate) | |
(defn vitality | |
"Vitality of city." | |
[city]) | |
(defn owner | |
"Owning city. None is returned if no owner exists." | |
[city]) |
(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) |
Clojure 1.7.0-beta2 | |
;; ns-unmap doesn't fully take effect on uses of the unmapped var in the same compilation unit: | |
user=> (let [] (ns-unmap 'user 'first) first) | |
#object[clojure.core$first__4107 0x4b8729ff "clojure.core$first__4107@4b8729ff"] | |
;; ...but has taken effect by the time the next top level form is compiled: | |
user=> first | |
CompilerException java.lang.RuntimeException: Unable to resolve symbol: first in this context, compiling:(NO_SOURCE_PATH:0:0) |
(defn tag [tags the-var] | |
(binding [*ns* nil] | |
(doseq [tag tags] | |
(intern (in-ns tag) (.sym the-var) @the-var)))) | |
(tag '[A B C] | |
(defn foo [a b] | |
(+ a b))) | |
(A/foo 5 10) |
: site-counter ( literal-int -- int ) | |
here cell - { addr } \ store in 'addr' the address of the literal int preceding this in the user's code | |
postpone dup \ compile code to ...dup the int at the top of the data stack | |
postpone 1+ \ ...increment it | |
addr postpone literal \ ...push the above 'addr' onto the data stack | |
postpone ! \ ...copy the incremented value INTO THE USERS CODE | |
; immediate \ do all this at compile time | |
\ Now for a "normal" word defintion | |
: bar ( -- ) |