Re: Another defmult VS defn query

2009-10-10 Thread Robert Stehwien
Thanks John. I mined contrib for java-util/file and duck-streams for several functions as well. http://github.com/rstehwien/clojure-rstehwien-utils/blob/master/src/main/clojure/com/arcanearcade/clojure/utils/file_utils.clj Tomorrow I'll add a bunch more file functions and tests. On Thu, Oct 8, 2

Re: Another defmult VS defn query

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 10:25 AM, Robert Stehwien wrote: > (defn mv2 [from to] > (let [f (if (= (class from) File) from (File. from)) > t (if (= (class to) File) from (File. to))] > (println "transformed to File"))) > ITYM t (if (= (class to) File) to (File. to))] for that

Re: Another defmult VS defn query

2009-10-08 Thread Robert Stehwien
On Thu, Oct 8, 2009 at 9:45 AM, Tom Faulhaber wrote: > > Check out clojure.contrib.duck-streams/reader and clojure.contrib.duck- > streams/writer (http://richhickey.github.com/clojure-contrib/duck- > streams-api.html). > > They'll give you a java.io.BufferedReader or a java.io.PrintWriter > which

Re: Another defmult VS defn query

2009-10-08 Thread Tom Faulhaber
Check out clojure.contrib.duck-streams/reader and clojure.contrib.duck- streams/writer (http://richhickey.github.com/clojure-contrib/duck- streams-api.html). They'll give you a java.io.BufferedReader or a java.io.PrintWriter which is usually what you want with a file. If you have some other use,

Re: Another defmult VS defn query

2009-10-08 Thread lpetit
Oh, maybe this as-file method already exists in clojure.contrib, honestly I don't know and don't have the time to search right now, regards, -- laurent On 8 oct, 16:41, Laurent PETIT wrote: > Suggestion : > > move and generalize the problem by creating an as-file multifn that may take > String

Re: Another defmult VS defn query

2009-10-08 Thread Laurent PETIT
Suggestion : move and generalize the problem by creating an as-file multifn that may take String, File , and maybe other things later ... (defmulti as-file type) (defmethod as-file String [from] (File. from)) (defmethod as-file File [from] from) (defn mv [from to] (let [ [from to] (map as-file

Another defmult VS defn query

2009-10-08 Thread Robert Stehwien
Here is another question on when you would use a multi-method. I want the mv function to accept a java.io.File or a String for either of the two parameters and here are the options I came up with: -(defmulti mv (fn [from to] [(class from) (class to)])) (defmethod mv [String String] [from to]