adapted from CLJ-1997
A common usage of gen/let might look something like this:
(gen/let [a gen-a| (ns user.test | |
| (:require | |
| [clojure.test :refer [deftest is]] | |
| [clojure.test.check.results :as results] | |
| [clojure.test.check.generators :as gen] | |
| [clojure.test.check.properties :as prop] | |
| [clojure.test.check.clojure-test :refer [defspec]])) | |
| (def gen-lazy-flatten-merge-by-keyfn | |
| (gen/elements [identity - #(mod % 17)])) |
| #+TITLE: What Are All These Class Files Even About?, and Other Stories | |
| #+AUTHOR: Gary Fredericks | |
| #+EMAIL: fredericksgary@gmail.com | |
| #+DATE: 2018-11-30, Clojure/conj | |
| #+CATEGORY: CONJ | |
| * Latex Prelude | |
| #+LaTeX_CLASS: beamer | |
| #+LaTeX_CLASS_OPTIONS: [presentation] | |
| #+BEAMER_THEME: Madrid |
| #!/usr/bin/env bash | |
| #! top-of-file comments can be written using more #! lines, which | |
| #! is a valid comment in both clojure and bash | |
| ":";# alternately this works too | |
| #! The construction below uses cross-language syntactic hackery to | |
| #! specify the -Sdeps arg in a part of the file that's interpreted | |
| #! by clojure as clojure syntax (i.e., not a line comment), so it |
| (ns user.bijections | |
| (:refer-clojure :exclude [-> comp update]) | |
| (:require [clojure.core :as core] | |
| [clojure.set :as set]) | |
| (:import (java.util UUID))) | |
| ;; | |
| ;; Motivation: | |
| ;; | |
| ;; - avoid the edge cases inherent in allowing multiple |
| # Creates a git repo with 2^N files. N is the only arg. Creates a | |
| # bare repo called "files". | |
| require 'digest/sha1' | |
| require 'zlib' | |
| def filename(id) | |
| "objects/#{id[0...2]}/#{id[2..-1]}" | |
| end |
| ;; goals: | |
| ;; - unbounded distribution (arbitrarily large bigints can be generated, | |
| ;; even for small `size`) | |
| ;; - but respects `size` -- with larger `size`, larger numbers are likely | |
| ;; to be generated | |
| ;; - has a roughly 0.1% chance of generating an integer larger than | |
| ;; Double/MAX_VALUE (2^1024) | |
| ;; sizing background: https://github.com/clojure/test.check/blob/master/doc/growth-and-shrinking.md |
| ;; | |
| ;; 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 user.defn+spec | |
| (:require [clojure.spec :as s])) | |
| (defn non-&-sym? [x] (and (symbol? x) (not= '& x))) | |
| (s/def ::arglist | |
| (s/cat :normal-args (s/* (s/cat :name non-&-sym? | |
| :spec-form (s/? (s/cat :- #{:-} | |
| :spec ::s/any)))) | |
| :varargs (s/? (s/cat :& #{'&} |