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.
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
(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? |
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 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. |
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
;; 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)) |
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
;reagent input two way binding with chinese characters . | |
;reagent 中文输入问题 |
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
;; 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 |
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 '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, |
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 atom? [x] | |
(not (list? x))) | |
(def car first) | |
(def cdr next) | |
(def add1 inc) | |
(def sub1 dec) | |
(defn lat? [lst] | |
(every? atom? lst)) |
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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 |
NewerOlder