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
;;; The following version works with any seq-able (not only Strings), but hardwires | |
;;; function = for equality testing of seq values (rather good default IMHO), but also | |
;;; hardwires the cost of 1 for either element insertion, deletion, or swap. | |
;;; | |
;;; It is functional, it does not use arrays, nor a MxN matrix, just the required data | |
;;; for computing a given "row" of the "virtual matrix" (e.g. the previous row) | |
;;; | |
;;; I'm quite sure it can still be improved for better readability and performance | |
;;; without loosing any of the above mentioned characteristics. |
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
; todo | |
; done 1. emit text deltas, not plain text replacement (or IDEs will not like it) | |
; done 2. have a story for invalid parsetrees : just do nothing : currently = paredit deactivated if error from start-of-file to area of paredit's work | |
; 3. use restartable version of the parser | |
; 4. make paredit optional in ccw | |
; 5. prepare a new release of ccw | |
; 6. write with clojure.zip functions the close-* stuff | |
; 7. write the string related stuff | |
; ... ? | |
; . add support for more clojure-related source 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
; Daniel Shiffman's initial example in his PVector + Processing Tutorial | |
; re-written in clojure | |
(ns example1 | |
(:use [rosado.processing] | |
[rosado.processing.applet])) | |
(set! *warn-on-reflection* true) | |
(def x (atom 100)) |
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 ^{:private true :macro true} assert-args #'clojure.core/assert-args) | |
#'user/assert-args | |
=> (defmacro | |
let-unless | |
"Apply the bindings and then the body like clojure.core/let would do, unless error-fn, | |
applied to any intermediate result, returns logical true, | |
in which case no more binding will be evaluated, and the return value will be the result | |
of applying handler-fn to the result of error-fn" | |
{:arglists "([error-fn handler-fn bindings & body])"} | |
[error-fn handler-fn bindings & body] |
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 net.cgrand.parsley.fold | |
(:require [net.cgrand.parsley.util :as u])) | |
+(defn make-leaf [s] | |
+ (memoize | |
+ (fn [view] | |
+ ((:unit view) s)))) | |
+ | |
+(defn make-node [tag children] | |
+ (memoize |
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 ^{:doc "Conway's Game of Life."} | |
game-of-life) | |
;; Core game of life's algorithm functions | |
(defn neighbours | |
"Given a cell natural identifier, returns the natural identifiers | |
of the neighbours of the cell. | |
In this implementation, the natural identifier of the cell is its [x, y] | |
coordinates." |
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 primes [] | |
((fn primes [candidate seen] | |
(lazy-seq | |
(letfn [(prime? [candidate] (when-not (some #(zero? (rem candidate %)) seen) candidate))] | |
(when-let [candidate (some prime? (iterate inc candidate))] | |
(cons candidate (primes (inc candidate) (cons candidate seen))))))) | |
2 ())) | |
(fact | |
(primes 1) => (2) |
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 challenge.weights | |
(:require [clojure.contrib.combinatorics :as c])) | |
(defn weigh? [i l r] | |
(let [l-weight (apply + i l)] | |
(some #(when (= l-weight (apply + %)) [l %]) (set (c/subsets r))))) | |
(defn diff [l1 l2] | |
(reduce (fn [l i] | |
(let [[b [f & r]] (split-with (complement #{i}) l)] |
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
;; Note 1: in a real project, would have had 3 files: one for the code, one for the tests, one for the test data | |
;; Note 2: you can test online at http://tryclj.com/ : copy/paste the (do ...) encapsulating the 3 defs (lines 7 to 21). | |
;; Then hit Enter to evaluate. Then type (main), then hit Enter to evaluate. | |
(ns foobarqiz) | |
(do ;; trick to ease the use of copying/pasting into http://tryclj.com | |
(def data (sorted-map 7 "Qix", 5 "Bar", 3 "Foo")) | |
(defn serialize |
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
;; Note 1: in a real project, would have had 3 files: one for the code, one for the tests, one for the test data | |
;; Note 2: you can test online at http://tryclj.com/ : copy/paste the (do ...) encapsulating the 3 defs (lines 8 to 55). | |
;; Then hit Enter to evaluate. Then type (main), then hit Enter to evaluate. | |
(ns foobarqix | |
(:require [clojure.string :as str])) | |
(do ;; trick to ease the use of copying/pasting into http://tryclj.com | |
(def FBQ |