Skip to content

Instantly share code, notes, and snippets.

(defmacro let-map
"Creates a hash-map which can refer to the symbols of the names of the keys
declared above."
[& kvs]
(assert (even? (count kvs)))
(let [ks (take-nth 2 kvs)
sym-ks (map (comp symbol name) ks)
vs (take-nth 2 (rest kvs))]
`(let ~(vec (interleave sym-ks vs))
~(apply hash-map (interleave ks sym-ks)))))
@frenchy64
frenchy64 / schema.md
Created August 11, 2014 06:55
Schema vs core.typed

Schema

I think of Schema as a runtime contracts library (I believe it does coercion and validation, but they seem related to me).

Pros

  • small barrier to entry, thus immediately useful
    • just add a contract/coercion to a function and you're off
  • can manipulate contracts as regular clojure data
  • documentation
@noidi
noidi / code.clj
Last active August 29, 2015 14:05 — forked from krisajenkins/code.clj
;;; Changes:
;;; - Annotate the parameter of the lambda given to filter. This was the cause of the error.
;;; - Change the last parameter of lookup-by from Seq to Seqable to allow it to work with vectors.
;;; - Replace (IFn [a -> b]) with [a -> b]. They're equivalent.
(t/ann lookup-by (t/All [a b]
[b [a -> b] (t/Option (t/Seqable a)) -> (t/Option a)]))
(defn lookup-by
"Convenience filter. Returns the first item in coll where (= value (lookup-fn item))"
@mrb
mrb / chords.clj
Last active August 29, 2015 14:05
core.logic db chords exercise
(ns chords.core
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]
[clojure.core.logic.fd :as fd]
[clojure.core.logic.pldb :as pldb]
[fipp.edn :refer (pprint) :rename {pprint fipp}]))
(pldb/db-rel note-name ^:index p)
(pldb/db-rel octave ^:index p)
(pldb/db-rel note ^:index p1 ^:index p2)
@tel
tel / T.hs
Last active August 29, 2015 14:06
Transducers with explicit local state
{-# LANGUAGE GADTs, RankNTypes #-}
import Control.Applicative
import Control.Category
import Data.List (foldl')
import Data.Profunctor
import Prelude hiding ((.), id)
-- | Explicit state-passing Moore machine
data Moore i o where
@pleasetrythisathome
pleasetrythisathome / silk.cljx
Created October 7, 2014 19:05
some code stripped out of a project showing use of silk for isomorphic routing
(ns router
#+cljs (:require-macros [cljs.core.match.macros :refer [match]])
(:require [domkm.silk :as silk]
[clojure.string :as str]
#+clj [content :as content]
#+clj [drivers.email :as email]
#+clj [clojure.core.match :refer [match]]
#+clj [compojure.core :as compojure :refer [defroutes GET POST PUT DELETE]]
#+clj [compojure.route :as route]
#+clj [com.stuartsierra.component :as component]
@qerub
qerub / fancy-defn.clj
Last active August 29, 2015 14:07
[Clojure] fancy-defn: Proof of concept of schema.core/defn augmented with automatically generated clojure.core.typed annotations via circle.schema-typer
(ns fancy-defn
(:require [schema.core :as s]
[clojure.core.typed :as t]
[circle.schema-typer :as st]))
;; Schemas created with s/defn end up using this.
(defmethod st/convert schema.core.One [schema]
(assert (= false (:optional? schema))) ;; No support for optional arguments yet.
(st/convert (:schema schema)))
@loganlinn
loganlinn / schema_extensions.clj
Last active August 29, 2015 14:10
variants in schema extensions
(ns schema-client.schema-extensions
"Schemas representing abstract classes and subclasses"
(:use plumbing.core)
(:require
[clojure.string :as str]
[plumbing.map :as map]
[schema.core :as s]
[schema.utils :as utils]
[schema.macros :as sm]))
anonymous
anonymous / gist:00b4c39f022d00943a64
Created December 11, 2014 12:29
(defvar my-helm-source-do-ag
`((name . "the silver searcher")
(candidates-process . helm-ag--do-ag-candidate-process)
(persistent-action . helm-ag-persistent-action)
(action . (("Open File" . helm-ag--action-find-file)
("Open File Other Window" . helm-ag--action--find-file-other-window)))
(no-matchplugin)
(nohighlight)
(requires-pattern . 2)
(candidate-number-limit . 200)))
; A Field Guide to
; Genetic Programming
; http://www.lulu.com/items/volume_63/2167000/2167025/2/print/book.pdf
(defn f2-1
"Figure 2.1 max(x+x, x+3*y)"
[x y]
(max (+ x x)
(+ x
(* 3 y))))