Skip to content

Instantly share code, notes, and snippets.

View ck's full-sized avatar
💭
I may be slow to respond.

ck ck

💭
I may be slow to respond.
  • United States
  • 15:06 (UTC -04:00)
View GitHub Profile
@ck
ck / lenses.clj
Created December 29, 2020 21:56 — forked from ctford/lenses.clj
A Clojure lens implementation based on focus and fmap.
(ns shades.lenses)
; We only need three fns that know the structure of a lens.
(defn lens [focus fmap] {:focus focus :fmap fmap})
(defn view [x {:keys [focus]}] (focus x))
(defn update [x {:keys [fmap]} f] (fmap f x))
; The identity lens.
(defn fapply [f x] (f x))
(def id (lens identity fapply))
@ck
ck / test.clj
Created June 25, 2013 11:54 — forked from adambard/test.clj
; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)
@ck
ck / gist:3226202
Created August 1, 2012 11:54 — forked from swannodette/gist:3217582
sudoku_compact.clj
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
(defn init [vars hints]
@ck
ck / clojure-nyc-meetup-notes-20120718.md
Created July 21, 2012 02:41 — forked from noahlz/clojure-nyc-meetup-notes-20120718.md
Rough Notes from the July 18 Clojure NYC Meetup

Organizing Clojure Projects

Presented by @stuartsierra

Stuart presented using a deck created with org-html-slideshow, a Clojure library for formatting org-mode notes as HTML slides.

General Code Structure / Organization
  1. Be careful not to make function calls across component boundaries.
  2. Protocols should be minimalistic. They should have the fundamental operations of your component.
@ck
ck / gist:2846903
Created May 31, 2012 22:42 — forked from stuarthalloway/gist:2002582
Datomic extent query
;; Datomic example code
;;
;; The extent of entity ?x is all datoms that are about ?x.
;; Drop this into your rules.
;;
;; Demonstrates
;;
;; 1. recursive query (extent calls itself)
;; 2. disjunction (different extent bodies are ORed)
;; 3. component attributes (e.g. your arm is a component, your brother isn't)
@ck
ck / gist:2652983
Created May 10, 2012 13:27 — forked from stuarthalloway/gist:2645453
Datomic queries against Clojure collections
;; Datomic example code
(use '[datomic.api :only (db q) :as d])
;; ?answer binds a scalar
(q '[:find ?answer :in ?answer]
42)
;; of course you can bind more than one of anything
(q '[:find ?last ?first :in ?last ?first]
"Doe" "John")
@ck
ck / gist:2030140
Created March 13, 2012 17:42 — forked from stuarthalloway/gist:1980351
frinj unit conversion running inside a Datomic datalog query
;; lein settings
(defproject foo "1.0.0-SNAPSHOT"
:description "Test App"
:dependencies [[com.datomic/datomic "0.1.2678"]
[frinj "0.1.2" :exclusions [org.clojure/clojure]]])
;; load libs
(use 'frinj.core 'frinj.calc)
(frinj-init!)
(use '[datomic.api :only (q db) :as d])
@ck
ck / simplifier.clj
Created February 13, 2012 12:36 — forked from alandipert/simplifier.clj
A Simplifier for all Expressions
;; A Simplifier for all Expressions
;; Example:
;; (simplify '(* 1 (+ x (- y y)))) ;=> x
;; (simplify '(and a (and (and) b))) ;=> (and a b)
;; See section 4.4, "Syntactic Abstraction" of Norvig and Pitman's
;; "Tutorial on Good Lisp Programming Style":
;; http://norvig.com/luv-slides.ps
@ck
ck / gist:1670187
Created January 24, 2012 13:31 — forked from swannodette/gist:1667847
hierarchy.clj
(ns hierarchy.core
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
(def order [:domain :kingdom :phylum :class :order :family :genus :species])
(def homo-sapiens
{:domain :eukarya
:kingdom :animalia-metazoa
:phylum :chordata
@ck
ck / part1.clj
Created October 9, 2011 15:58 — forked from frenchy64/part1.clj
Evolving a logic programming language
;; Evolving a logic programming language
;; Based on sketches at https://github.com/frenchy64/Logic-Starter/blob/master/src/logic_introduction/decl_model.clj
;; A logic statement reduces to true or false.
true
;=> true
false
;=> false