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
(defproject my-proj "0.1.0-SNAPSHOT" | |
:description "FIXME: write" | |
:dependencies [[org.clojure/clojure "1.2.0"] | |
[org.clojure/clojure-contrib "1.2.0"]] | |
:dev-dependencies [[swank-clojure "1.2.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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>How to get started with Clojure in Emacs</title> | |
<style> | |
body { | |
font-family: sans-serif; | |
width: 800px; |
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
(deftest single-are-style | |
(testing "prefix, command and single parameter" | |
(let [result (msg/parse ":source COMMAND param")] | |
(are [key val] (= (get result key) val) | |
:source "source" | |
:command "COMMAND" | |
:params ["param"])))) | |
(deftest multiple-is-style | |
(testing "prefix, command and single parameter" |
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 se.raek.quirclj.message | |
(:refer-clojure :exclude [format]) | |
(:use [clojure.contrib.def :only [defvar-]])) | |
(declare parse-params) | |
(defvar- message-regex | |
#"^(?::([^ ]+) +)?([^ ]+)(?: +(.+))?$") | |
(defn parse [s] |
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
datatype Term = Var of string | |
| Abs of string * Term | |
| App of Term * Term | |
fun replace (Var v) x y = if v = x then y else Var v | |
| replace (Abs (v, t)) x y = Abs (v, replace t x y) | |
| replace (App (l, t)) x y = App (replace l x y, replace t x y) | |
fun eval (App (Abs (p, b), x)) = eval (replace b p x) | |
| eval (App (App a, x)) = |
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 se.raek.validator | |
"A library for validating the values of maps. | |
This library is build around the concept of validators. A validator is a | |
function that takes a value and returns non-nil if it was valid and nil if | |
it was invalid. The non-nil value can be the same as the given value or a | |
processed version of it. For example, an integer validator might work as | |
follows (demonstrating validators' normalizing functionality): | |
(defn integer-validator [x] |
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 se.raek.lcug.web-example | |
(:use [net.cgrand.moustache :only [app]] | |
[ring.adapter.jetty :only [run-jetty]])) | |
(def messages (atom ())) | |
(def routes | |
(app | |
[""] "hi!" | |
["hello"] {:get [{:status 200 |
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 file-stored | |
"Creates an instance of ref-type with its value loaded from, and on changes | |
automatically stored in the file with the filename." | |
[ref-type filename] | |
(let [r (ref-type (read-string (slurp filename)))] | |
(add-watch r ::file-stored #(spit filename (pr-str %4))) | |
r)) |
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
(require 'paredit) | |
(eval-after-load 'paredit | |
'(progn (define-key paredit-mode-map (kbd "{") | |
'paredit-open-curly) | |
(define-key paredit-mode-map (kbd "}") | |
'paredit-close-curly) | |
(define-key paredit-mode-map (kbd "M-}") | |
'paredit-close-curly-and-newline))) |
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
(use 'clojure.walk) | |
(defn prefix-thingy [form] | |
(let [counter (atom -1)] | |
(postwalk (fn [x] | |
[(swap! counter inc) x]) | |
form))) | |
;; (prefix-thingy [[:a :b] [:c :d]]) | |
;; --> [6 [[2 [[0 :a] [1 :b]]] [5 [[3 :c] [4 :d]]]]] |