On Sun, Sep 7, 2008 at 2:55 PM, Tom Emerson <[EMAIL PROTECTED]> wrote:

> Hi folks,
> I'm trying to use the proxy support to provide a filter to
> java.io.File#listFiles and am not having any luck: I'm sure I'm doing
> something stupid, and would appreciate some tips. Here's what I'm doing:
>
> (import '(java.io File FilenameFilter))
>
> (def filter (proxy [FilenameFilter] []
>               (accept [dir name]
>                       (. name (endsWith "_2.jpg"))))
>
> (def the-dir (new File "/Users/tree/images"))
>
> (map #(. %1 getCanonicalPath)
>      (. the-dir (listFiles filter)))
>
>
> When I evaluate this, I get an IllegalArgumentException:
>
> java.lang.IllegalArgumentException: No matching method found: listFiles
> java.lang.IllegalArgumentException: No matching method found: listFiles
>  at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:62)
> at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:26)
>  at clojure.lang.Compiler$InstanceMethodExpr.eval(Compiler.java:1087)
> at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2568)
>  at clojure.lang.Compiler.eval(Compiler.java:3780)
> at clojure.lang.Repl.main(Repl.java:75)
>
> If I don't include the filter in the call to the listFiles method, then it
> works fine.
>

Did the def of filter succeed for you? When I tried your code, I got an
error "Name conflict, can't def filter because namespace: user refers
to:#'clojure/filter". Then if I proceed and try to do the map operation, I
get the no matching method found error because filter is the fn
clojure/filter, not a FilenameFilter.

--Shawn

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to