adapted from CLJ-1997
A common usage of gen/let
might look something like this:
(gen/let [a gen-a
(t/def-alias HTML-Atts (IPersistentMap t/Keyword String)) | |
(t/def-alias HTML | |
(Rec [HTML] | |
(U String | |
nil | |
(HVec [t/Keyword (U HTML (t/Seq HTML)) *]) | |
(HVec [t/Keyword HTML-Atts (U HTML (t/Seq HTML)) *])))) |
;; | |
;; This file is clojure code that draws itself in a swing buffer | |
;; (https://twitter.com/pjstadig/status/771152863410188288) | |
;; | |
(defn draw-in-swing-buffer | |
[s] | |
(let [panel (doto (javax.swing.JPanel.) | |
(.setLayout (java.awt.BorderLayout.))) | |
frame (doto (javax.swing.JFrame.) |
(def regular-quine | |
"A regular quine. Evals to itself." | |
'(let [thing '(list 'let ['thing (list 'quote thing)] | |
thing)] | |
(list 'let ['thing (list 'quote thing)] | |
thing))) | |
(= regular-quine (eval regular-quine)) ;; => true | |
(def counting-quine |
adapted from CLJ-1997
A common usage of gen/let
might look something like this:
(gen/let [a gen-a
(ns forty-two-doubles.core | |
(:require [clojure.walk :as walk] | |
[clojure.string :as string] | |
#?(:clj [com.gfredericks.doubles :refer [parse-double]]) | |
[forty-two-doubles.four :as four #?@(:cljs [:include-macros true])] | |
[plumbing.core :as p])) | |
(defn positive-infinity? | |
[x] | |
#?(:clj (= x Double/POSITIVE_INFINITY) |
(defn lazy-shuffle | |
"Returns a locally-shuffled lazy seq from the given collection. The first | |
arg has something to do with how it works so make sure it's a good one." | |
[window-size coll] | |
(let [[xs more] (split-at window-size coll)] | |
((fn self [v more] | |
(lazy-seq | |
(if (empty? more) | |
v | |
(let [[x & more] more |
(ns clojure-peg-memoization-example | |
"A followup to Sean Cribbs' presentation on packrat parsers: | |
https://github.com/seancribbs/pwl-chicago-1/ | |
The goal is to show that in an impure language like Clojure we can | |
bolt on memoization after the fact and get the same performance | |
advantage as the Haskell implementation without bending over | |
backwards -- i.e., we maintain the same algorithm structure as a | |
recursive descent parser. |
(defmacro for-all | |
"Like prop/for-all but runs :each fixtures around the expression." | |
[bindings expr] | |
`(prop/for-all ~bindings | |
((join-fixtures (::each-fixtures (meta ~*ns*))) | |
(fn [] ~expr)))) |
(defmacro gen-let | |
[bindings expr] | |
(if-let [[name gen & more] (seq bindings)] | |
`(gen/bind ~gen | |
(fn [~name] | |
(gen-let ~more ~expr))) | |
expr)) |
class PersistentList | |
attr_reader :length, :head, :tail | |
include Enumerable | |
EMPTY = Object.new | |
class << EMPTY | |
include Enumerable | |
def length; 0; end | |
def each(&block); end | |
def to_s; "()"; end | |
def cons(item); PersistentList.new(item, self); end |