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
;; You are right that the f function passed to update gets called only once. | |
;; However the value passed to it may be composite. | |
;; multifocals | |
=> (defn swap [[a b]] [b a]) | |
#'enliven.core.lenses/swap | |
=> (update {:a "A" :b "B" :c "C"} | |
(juxt :a :b) swap) | |
{:a "B", :b "A", :c "C"} |
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 only reason for the protocol is to have keywords behave as lenses | |
; it could have been hard coded in fetch/putback | |
(defprotocol Lens | |
(-fetch [l x]) | |
(-putback [l x v])) | |
(defn fetch [x l] (-fetch l x)) | |
(defn putback [x l v] (-putback l x v)) | |
(defn update [x l f & args] |
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 parsley2.core) | |
(defprotocol Asmable | |
(asm [x])) | |
(defrecord InlineAsm [ops] | |
Asmable | |
(asm [_] ops)) | |
(extend-protocol Asmable |
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 functions are missing, be it for char ranges or for lookaheads | |
; however this snippet demoes: | |
; * error-correction (the change in correction between the 3rd and 4th case shows that parsnip looks for a minimal deletion) | |
; * lookahead | |
=> (let [alpha (fn [c] (<= (int \a) (int c) (int \z))) | |
p (parser :map | |
{:map ["{" (* :sym (? :ws) :sym) "}"] | |
:ws (+ " ") | |
:sym [(+ (->InlineAsm [:PRED alpha])) | |
(->InlineAsm [:PEEK (complement alpha)])]})] |
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 lazy-reader [start prods] | |
(let [step (vm/stepper (asm/link (grammar start prods)))] | |
(fn self | |
([input] (self input (vector-tree-builder input))) | |
([input builder] | |
((fn f [state i] | |
(lazy-seq | |
(when (< i (count input)) | |
(let [state (step state i (nth input i))] | |
(if (when-let [stacks (get state -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
@@ -271,4 +271,5 @@ | |
name="%context.structEditingClojureSource.name" | |
description="%context.structEditingClojureSource.description" | |
+ parentId="ccw.ui.clojureEditorScope" | |
id="ccw.ui.clojureStructEditorScope"> | |
</context> | |
@@ -576,4 +577,16 @@ | |
<key | |
commandId="ccw.ui.edit.text.clojure.expand.selection.up" | |
+ contextId="ccw.ui.clojureStructEditorScope" |
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
package base; | |
public class GCD { | |
public static long gcd(long a, long b) { | |
while (a != b) { | |
if (a < b) b -= a; | |
else a -= b; | |
} | |
return a; |
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
From 0c89fecf532c7c73468164290af03bbed5559f3f Mon Sep 17 00:00:00 2001 | |
From: Christophe Grand <christophe@cgrand.net> | |
Date: Tue, 16 Sep 2014 13:36:36 +0200 | |
Subject: [PATCH] fix clojure benchmark | |
--- | |
.../arithmetic/EuclidianGcdMicroBenchmark.java | 8 ++++++++ | |
.../main/resources/snippets/clojure/arithmetic.clj | 23 +++++++++++++++++----- | |
2 files changed, 26 insertions(+), 5 deletions(-) |
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
; discussed here https://groups.google.com/d/msg/clojure-dev/cWzMS_qqgcM/7IAhzMKzVigJ | |
; nested reduced | |
=> (transduce (comp (take 1)) conj [:a]) | |
[:a] | |
=> (transduce (comp (take 1) (take 1)) conj [:a]) | |
#<Reduced@65979031: [:a]> | |
=> (transduce (comp (take 1) (take 1) (take 1)) conj [:a]) | |
#<Reduced@fcbc8d1: #<Reduced@60bea99a: [:a]>> | |
=> (transduce (comp (take 1) (take 1) (take 1) (take 1)) conj [:a]) |
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 mutabots | |
"Reimplementation of transducers, in terms of processing functions instead | |
of reducing functions. | |
tl;dr: reducing-fn based transducers are a special case, influenced by reducers, | |
of processing-fn based transducers. | |
In Clojure 1.7.0-alpha2, transducers are expressed in terms of the existing | |
concept of reducing functions. | |
To sum it up, a transducer has currently the signature : |