Skip to content

Instantly share code, notes, and snippets.

(cf (fn [m] (conj [0] (if m 1 2))))
; [(Fn [Any -> [(Value 0) (U (Value 1) (Value 2))]]) {:then tt, :else ff}]
(cf (fn [{:keys [a] :as m} c]
(merge m {:b (+ a c) :c c}))
['{:a Number} Number -> '{:a Number :b Number :c Number}])
; (Fn [(HMap :mandatory {:a Number}) Number -> (HMap :mandatory {:a Number, :b Number, :c Number})])
(cf (fn [m] (dissoc {:a 1 :b 2} (if m :a :b))))
; [(Fn [Any -> (U (HMap :mandatory {:a (Value 1)} :complete? true)
@c-spencer
c-spencer / core.clj
Last active December 23, 2015 02:49
Simple demo of type construction from Datomic with core.typed and a little glue
(defn create-type
"Extract a type from provided field idents stored in Datomic database at uri."
[uri type-name overrides]
(let [c (d/connect uri)
d (d/db c)
datomic-type-map {:db.type/string 'String
:db.type/ref 'Any}
mt (dt/q> :- [EntityID]
'[:find ?e
:in $ ?t-name
@c-spencer
c-spencer / datomic-annotations.clj
Last active December 24, 2016 21:45
A first pas at Datomic Types
(ns typed-datomic.types
(:use [clojure.core.typed])
(:import [clojure.lang Keyword Symbol]
[java.util Date]))
;; Type aliases
; Marker protocol to distinguish historical databases
(ann-protocol HistoryDB)
(defprotocol> HistoryDB)
@c-spencer
c-spencer / gist:6528482
Last active December 22, 2015 20:48
core.typed messings about
; trying to work around no update-in type
(defmacro typed-update-in [m [v] f]
`((ann-form update-in
(~'All [~'x ~'y]
[ (~'HMap :mandatory {~v ~'x}) (~'Vector* Keyword) [~'x ~'-> ~'y]
~'->
(~'HMap :mandatory {~v ~'y}) ]))
~m [~v] ~f))
; still causes an error because of the inner un-typed update-in
(defn Buffer [string]
(set! this.string string)
(set! this.pos 0)
undefined)
(defn Buffer.prototype.read1 []
(cond
(= this.pos this.string.length)
(do
(set! this.pos (+ this.pos 1))
(ns typingfun.core
(:require [clojure.core.typed :as t]))
(t/ann-protocol AddProtoc
adder [AddProtoc Number -> AddProtoc])
(t/defprotocol> AddProtoc
(adder [this amount]))
(t/ann-datatype Accumulator [t :- Number])
@c-spencer
c-spencer / preprocess-schema.clj
Last active December 10, 2015 05:28 — forked from anonymous/preprocess-schema.clj
Simple template expansion meta-definitions for Datomic
(defn extract-key [m k]
(when-let [value (k m)] [(dissoc m k) value]))
(defn expand-entry-id [entry]
(if (keyword? (:db/id entry))
(update-in entry [:db/id] d/tempid)
entry))
(defn expand-schema-entry [entry templates]
(if (and (map? entry) (:meta/templates entry))
(ns euler.problem-eleven
(:refer-clojure :exclude [==])
(use clojure.core.logic))
(def grid [ 8 2 22 97 38 15 0 40 0 75 4 5 7 78 52 12 50 77 91 8
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 4 56 62 0
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 3 49 13 36 65
52 70 95 23 4 60 11 42 69 24 68 56 1 32 56 71 37 2 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 3 45 2 44 75 33 53 78 36 84 20 35 17 12 50
(defmethod euler-problem 11 [_]
(let [number-grid
[ 8 2 22 97 38 15 0 40 0 75 4 5 7 78 52 12 50 77 91 8
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 4 56 62 0
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 3 49 13 36 65
52 70 95 23 4 60 11 42 69 24 68 56 1 32 56 71 37 2 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 3 45 2 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 2 62 12 20 95 63 94 39 63 8 40 91 66 49 94 21
gcc `pkg-config pangocairo --cflags --libs` pangocairotest.c -o pangocairotest
...
(gdb) run
Starting program: /Users/chris/Dev/node-canvas/pangocairotest
...
Program received signal EXC_BAD_ACCESS, Could not access memory.