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
;; given this data structure | |
(def data | |
[{:type :root, | |
:content | |
[{:line-type :comment, :text "#+title: Sample Org File"} | |
{:line-type :comment, :text "#+author: Seylerius"} | |
{:line-type :blank, :text ""} | |
{:line-type :paragraph, | |
:text "This is an attempt to test Org-Mode processing."} | |
{:line-type :blank, :text ""}]} |
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 specter.zip | |
(:use [com.rpl.specter.macros :only [defpath]] | |
[com.rpl specter]) | |
(:require [clojure [zip :as zip]])) | |
(def VECTOR-ZIP (view zip/vector-zip)) | |
(def NEXT (view zip/next)) | |
(def RIGHT (view zip/right)) | |
(def LEFT (view zip/left)) | |
(def DOWN (view zip/down)) |
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 'com.rpl.specter) | |
(use 'com.rpl.specter.macros) | |
(defprotocolpath TreeWalker []) | |
(extend-protocolpath TreeWalker | |
Object nil | |
clojure.lang.PersistentVector [ALL TreeWalker]) | |
(select [TreeWalker number?] [:a 1 [2 [[[3]]] :e] [4 5 [6 7]]]) |
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 MOVIES | |
[{:name "Lethal Weapon", :director "Paul Verhoeven", :rating 7.6} | |
{:name "RoboCop", :director "George P. Cosmatos", :rating 7.5} | |
{:name "Bad Movie", :director "James Cameron", :rating 4.2} | |
{:name "Great Movie", :director "James Cameron", :rating 10.0} | |
{:name "Lethal Weapon 3", :director "Ted Kotcheff", :rating 6.6} | |
{:name "Rambo III", :director "John McTiernan", :rating 5.4} | |
{:name "The Terminator", :director "Peter MacDonald", :rating 8.1} | |
{:name "Titanic", :director "James Cameron", :rating 8.3} |
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
[{:a 2 :b 3} {:a 1} {:a 4}] |
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 pay-fee [world] | |
(transfer world | |
[:people ALL :money] | |
[:bank :funds] | |
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
(def DATA {"a" [{"b" 1} {"b" 2}] "b" 11}) | |
;; Selectors that require parameters can be precompiled *without* the parameters. | |
;; The parameters are supplied later. | |
(def path (comp-paths keypath ALL keypath)) | |
;; These two selections are equivalent | |
(select (path "a" "b") DATA) | |
(select [(keypath "a") ALL (keypath "b")] DATA) |
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
(-invoke [this p01 p02 p03 p04 p05 p06 p07 p08 p09 p10 | |
p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 | |
rest] | |
(let [a (object-array | |
(concat | |
[p01 p02 p03 p04 p05 p06 p07 p08 p09 p10 | |
p11 p12 p13 p14 p15 p16 p17 p18 p19 p20] | |
rest))] | |
(com.rpl.specter.impl/bind-params* this a 0)) | |
) |
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
(defprotocol TestProtocol | |
(tester [o])) | |
(let [t tester] | |
(defn another-tester [o] | |
(t o))) | |
(def another-tester2 tester) | |
(extend-protocol TestProtocol |
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
(defprotocol TestProtocol | |
(tester [o])) | |
(def tester-with-meta (with-meta tester {:a 1})) | |
(extend-protocol TestProtocol | |
String | |
(tester [o] (println "Strings work!"))) | |
(tester-with-meta "A") ;; Error |