Created
June 2, 2011 16:55
-
-
Save rik0/1004799 to your computer and use it in GitHub Desktop.
This file contains 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
>>> import example | |
>>> example.ClassExample.show([1, 2, 3]) | |
123 | |
>>> ce = example.ClassExample() | |
>>> ce.foo([1, 2, 3]) | |
3 |
This file contains 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
(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)) | |
This file contains 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
(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) |
This file contains 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 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) |
This file contains 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 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