Skip to content

Instantly share code, notes, and snippets.

@rik0
Created June 2, 2011 16:55
Show Gist options
  • Save rik0/1004799 to your computer and use it in GitHub Desktop.
Save rik0/1004799 to your computer and use it in GitHub Desktop.
>>> import example
>>> example.ClassExample.show([1, 2, 3])
123
>>> ce = example.ClassExample()
>>> ce.foo([1, 2, 3])
3
(ns example.ClassExample
(:gen-class
:name example.ClassExample
:extends Object
:implements []
:methods [[foo [java.util.Collection] int]
^{:static true} [show [java.util.Collection] void]])
(:import (java.util Collection)))
(defn -foo [this coll]
(let [coll (seq coll)]
(if coll
(count coll)
-1)))
(defn show [coll]
(if (seq coll)
(do
(print (first coll))
(recur (rest coll)))
(println "")))
(defn -show [coll]
(show coll))
(take 10 (rember/multirember 4 (iterate inc 0)))
; Evaluation aborted.
(defn lazy-multirember [a lat]
(letfn
[(multirember-aux [source]
(lazy-seq
(if (seq source)
(if (= (first source) a)
(multirember-aux (rest source))
(cons (first source)
(multirember-aux (rest source))))
'())))]
(multirember-aux lat)))
(take 10 (rember/lazy-multirember 4 (iterate inc 0)))
; => (0 1 2 3 5 6 7 8 9 10)
(defn rember [a lat]
(cond
(empty? lat) '()
(= (first lat) a) (rest lat)
:else (cons
(first lat)
(rember a (rest lat)))))
(rember 4 '(1 2 3 4 5 6 4))
; => (1 2 3 5 6 4)
(defn multirember [a lat]
(letfn
[(multirember-aux [source sink]
(if (seq source)
(if (= (first source) a)
(recur (rest source)
sink)
(recur (rest source)
(conj sink (first source))))
sink))]
(multirember-aux lat [])))
(multirember 4 '(1 2 3 4 5 6 4))
; => [1 2 3 5 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment