This file contains hidden or 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
>>> if True: | |
... for i in [1, 2]: | |
... print(i) | |
... else: | |
... print("else") | |
... | |
1 | |
2 | |
else | |
>>> def foobar(): |
This file contains hidden or 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
# lazyseq.py | |
class LazySeq(object): | |
def __init__(self, f): | |
self.f = f | |
self.seq = [] | |
def next(self): | |
res = self.f(self.seq) | |
self.seq.append(res) |
This file contains hidden or 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
user=> (#{} 1 "not found") | |
ArityException Wrong number of args (2) passed to: PersistentHashSet clojure.lang.AFn.throwArity (AFn.java:429) | |
user=> ((transient #{}) 1 "not found") | |
"not found" |
This file contains hidden or 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- symbol->Class [resolved-symbol original-symbol] | |
(if (class? resolved-symbol) | |
(-> (str resolved-symbol) | |
(split #"\.") | |
last | |
symbol) | |
original-symbol)) | |
(defn- do-resolve [sym] | |
(let [r (resolve sym)] |
This file contains hidden or 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 Log | |
(info [args])) | |
; We wanted to do this | |
(deftype TaggedLogger [metadata] | |
Log | |
(info [args] (apply clojure.tools.logging/info (conj metadata args)))) | |
; but info et al. are macros so we can't use apply here | |
; Then I wrote this macro in order to wrangle the problem |
This file contains hidden or 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 following fails, it seems to be related to using try..finally and returning this | |
(defprotocol Foo | |
(-bar [this])) | |
(deftype Baz [^:volatile-mutable -oof] | |
Foo | |
(-bar [this] | |
(try | |
(set! -oof "something") |
This file contains hidden or 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 coords({x1, y1}, {x2, y2}) when x1 == x2 or y1 == y2 or abs(x1 - x2) == abs(y1 - y2) do | |
do_coords({x1, y1}, {x2, y2}, []) | |
end | |
def coords(_, _), do: raise "invalid" | |
defp do_coords({fromx, fromy}, {tox, toy}, acc) when fromx == tox and fromy == toy, do: tl(acc) | |
defp do_coords({fromx, fromy}, {tox, toy}, acc) do | |
newx = gen_next(fromx, tox) |
This file contains hidden or 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
" Trip trailing whitespace | |
function! Trim() | |
exe "normal mz" | |
%s/\s*$// | |
exe "normal `z" | |
exe "normal zz" | |
endfunction | |
command! -nargs=0 Trim :call Trim() | |
nnoremap <silent> <Leader>tw :Trim<CR> |
This file contains hidden or 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
; try is a special form that seems to not allow def'd classes to be used | |
; for example: | |
; | |
; (def illegal-argument IllegalArgumentException) | |
; | |
; (try (catch illegal-argument _)) | |
; | |
; will raise the following exception: | |
; Unable to resolve classname: illegal-argument |
This file contains hidden or 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
(let [next-public (ns-publics 'clojure.next) | |
core-public (ns-publics 'clojure.core) | |
[compl not-compl] (let [s (set (keys next-public))] | |
(loop [ks (keys core-public) | |
compl '() | |
not-compl '()] | |
(if (empty? ks) | |
[compl not-compl] | |
(if (contains? s (first ks)) | |
(recur (rest ks) (conj compl (first ks)) not-compl) |
NewerOlder