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 <laurent.pe...@gmail.com> wrote:
> 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 [from to]) ]
>     (println "transformed to file"))
>
> cheers,
>
> --
> laurent
>
> 2009/10/8 Robert Stehwien <rstehw...@gmail.com>
>
> > 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] (println "Both strings"))
> > (defmethod mv [File File] [from to] (println "Both files"))
> > (defmethod mv [File String] [from to] (println "File String"))
> > (defmethod mv [String File] [from to] (println "String File"))
>
> > (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")))
> > -----
>
> > While I find that multi-methods allowing me to do the above exceedingly
> > cool, would it be more idomatic to just use the let and create a File if
> > passed a String.  Am I doing "too much work" for something relatively
> > simple.
>
> > The multi-method does have better (IMHO) errors when passed (mv ["foo"]
> > "bar"):
> > -----
> > No method in multimethod 'mv' for dispatch value:
> > [clojure.lang.LazilyPersistentVector java.lang.String]
> >   [Thrown class java.lang.IllegalArgumentException]
> > -----
>
> > This would tell me that I could write another multi-method that could move
> > multiple files from different locations passed in as a sequence to one
> > destination... which I didn't think I needed but could be pretty handy now
> > that I think on it.
>
> > --Robert
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to