Skip to content

Instantly share code, notes, and snippets.

comment delim "#\|" "\|#" multiline nested
comment start ";"
vardef SPECIALCHAR = '\\.'
environment string delim "\"" "\"" begin
specialchar = $SPECIALCHAR
end
# broken:
;; wouldn't it be nice if...
(def-type-multis DataRow
(get-column-names [this])
(get-value [this column-name]))
(defmethods DataRow
clojure.lang.Associative
(get-column-names [this]
(range (count this)))
(set! *print-length* 103)
(set! *print-level* 15)
(use '[clojure.contrib.repl-utils :only [show add-break-thread!]])
(use '[clojure.pprint :only []])
(def *pprint*)
(defn my-repl []
(add-break-thread!)
(binding [*pprint* true]
(clojure.main/repl
The first two chars of each of the lines below are not actually
included on the wire but just indicate the direction of communication
for the purposes of this illustration. A leading > means data sent
from client to server, < is from server to client. Note these are
from the point of view of the REPL client. The REPL server may
actually see something slightly different because of intermediate
STOMP proxies.
> CONNECT
> login: chouser
(defprotocol Spinnable
(spin [this] "Return a seq walking the opposite direction as this"))
(defn iter-bi [x f b]
(reify
Spinnable
(spin [_] (iter-bi x b f))
clojure.lang.ISeq
(first [_] x)
(more [_] (iter-bi (f x) f b))
;; This is very buggy. Barely works at all.
(defmacro delegate-proxy [bases args delegate & user-methods]
(let [x (gensym "delegate_")
user-method-names (set (map first user-methods))
args-map (reduce (fn [tbl meth]
(update-in tbl [(symbol (.getName meth))
(count (.getParameterTypes meth))]
conj
(.getParameterTypes meth)))
@Chouser
Chouser / avoid-force-print.clj
Created September 21, 2010 13:38
Avoid forcing lazy seqs when printing
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
; modified by Chris Houser
(require '[clojure.contrib.reflect :as hack])

Fun and engaging talk. Thanks for putting it together and introducing Clojure to even more people.

I took a few notes while listening, and while I understand the purpose just to give a taste of the language and not to be hyper-correct, I thought it might be useful to ... um, adjust ... a few details for those that are interested:

  • 'def' creates or overrides a Var. It's use is not undefined, but using it inside a function definition or loop is discouraged. There
(.setDefaultRenderer table Object
(proxy [javax.swing.table.DefaultTableCellRenderer] []
(getTableCellRendererComponent [tbl obj isSelected hasFocus r c]
(let [{:keys [level]} (nth rows r)]
(doto this
(.setForeground (cond
(<= level 0) Color/white
(<= level 10) Color/blue
(<= level 20) Color/red
(<= level 30) Color/magenta
;; The Alternate Abomination:
(defmacro dolet [[x1 lcl expr :as x] & more]
(if (= x1 'let)
`(let [~lcl ~expr]
(dolet ~@more))
(if (empty? more)
x
`(do ~x (dolet ~@more)))))