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 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]) |
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 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)) |
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
; 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 |
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 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) |
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 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 |
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
(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) |
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
; adapted from clojure.core.incubator | |
(defn dissoc-in | |
"Dissociates a number of entries from the object at the given path, | |
removing empty maps on the path. | |
e.g. (dissoc-in {:a {:b {:e 6} :c 6}} [:a :b] [:e]) -> {:a {:c 6}}" | |
[m [k & ks :as keys] rems] | |
(if k | |
(if-let [nextmap (get m k)] | |
(let [newmap (dissoc-in nextmap ks rems)] | |
(if (seq newmap) |
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
defmodule Plural do | |
require Record | |
Record.defrecordp :xmlAttribute, Record.extract(:xmlAttribute, from_lib: "xmerl/include/xmerl.hrl") | |
Record.defrecordp :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl") | |
defmacro __using__(_env) do | |
quote do | |
@before_compile Plural | |
Module.register_attribute(__MODULE__, :plurals, accumulate: true) |
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
LANG=en | |
This is a comment that precedes the strings. | |
@test message | |
Hello from the translator. | |
-- and this is a comment inbetween strings | |
@test message 2 |
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
# current | |
("You came in " <> case(plural("en", :ordinal, args[:place])) do | |
"few" -> | |
to_string(args[:place]) <> "rd" | |
"one" -> | |
to_string(args[:place]) <> "st" | |
"other" -> | |
to_string(args[:place]) <> "th" | |
"two" -> | |
to_string(args[:place]) <> "nd" |