Skip to content

Instantly share code, notes, and snippets.

(def shapes #{:box :triangle :circle :pentagon})
(def colors #{:yellow :green :gray :white :blue :purple})
(def edge-types #{:directed :undirected})
(def colored?
(fn [attr]
(and keyword?
(contains? colors attr))))
(def shape?
@dpurjon
dpurjon / core-test.clj
Created September 26, 2017 20:26
A walktrough λ-calculus with Clojure
(ns lambda.core-test
(:require [clojure.test :refer :all]))
;; A walktrough λ-calculus with Clojure
;; based on Greg Michaelson book "An introduction to to functional programming through lambda calculus"
;; !!! DISCLAIMER !!!
;; ------------------
;; This document is 100% based on Greg Michaelson's book.
@ransomw
ransomw / fp_snippets.clj
Created January 22, 2017 05:36
functional programming clojure snippets
;; helper that's like clojure.core/partial, except
;; it partially applies the function to its args in reverse order
(defn partial-reverse [f & partial-args]
(comp
(partial
apply
(apply partial
(cons (comp (partial apply f) reverse list)
partial-args)))
reverse list))
@lsgrep
lsgrep / cljs clj
Last active July 19, 2022 21:28
reagent input with Chinese characters
;reagent input two way binding with chinese characters .
;reagent 中文输入问题
@john2x
john2x / 00_destructuring.md
Last active April 23, 2024 13:18
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@gdevanla
gdevanla / y-combinator-clojure.clj
Last active October 9, 2022 16:46
Y-Combinator in Clojure based on Jim Weirich's talk Y-NOT
;; This gist roughly transribes the demo
;; by Jim Weirich during his talk on Y-Combinator
;; called Y-Not.
;; http://www.infoq.com/presentations/Y-Combinator
;; Jim does a phenomenal job of explaining in the demo.
;; Therefore, this gist only attempts to provide
;; the code example from the poor quality video
;; The examples are simplified at some places
;; based on how I tried to understand it
@avsej
avsej / test.rb
Created July 18, 2012 12:48
Two phase commit for Couchbase. Version 2 (improved version of https://gist.github.com/3135796)
require 'rubygems'
require 'couchbase'
def transfer(source, destination, amount)
cb = Couchbase.bucket
# prepare transaction document
id = cb.incr("transaction:counter", :create => true)
trans_id = "transaction:#{id}"
cb.set(trans_id, {"source" => source, "destination" => destination,
@gar3thjon3s
gar3thjon3s / littleschemer.clj
Created September 24, 2011 21:06
Little schemer in clojure
(defn atom? [x]
(not (list? x)))
(def car first)
(def cdr next)
(def add1 inc)
(def sub1 dec)
(defn lat? [lst]
(every? atom? lst))
@clintel
clintel / gist:1155906
Created August 19, 2011 02:40
Fenced code in bullet lists with GitHub-flavoured MarkDown??

Fenced code blocks inside ordered and unordered lists

  1. This is a numbered list.

  2. I'm going to include a fenced code block as part of this bullet:

    Code
    More Code
    
@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world