Hi all. If I want an API docs on an "object", say, http://clojure.java.io/file, to check the functions and return types, where to I get this? All I find is surface stuff like: https://clojure.github.io/clojure/clojure.java.io-api.html But this doesn't give me infos on functions and return types. Hints / Links wozld be greatly appreciated.
PS: This doesn't help either: https://clojuredocs.org/clojure.java.io/file From AI generated code I know, there comes .IsDirectory and .isFile with http://clojure.java.io/file. Well... this lucky and totally random find is nice. An official API doc would be even better. Then I would know whether these functions return stuff like lazy seqs. But for the time being i'm stuck.
Please avoid splitting your message into multiple messages - it's much better to edit the original message or start a thread. Helps with avoiding unnecessary notifications and fragmenting the discussion across multiple threads.
is not an object, at least not in an OOP sense. It's just a function. You can check what it does with (doc ...) in your REPL:
user=> (doc )
-------------------------
([arg] [parent child] [parent child & more])
Returns a java.io.File, passing each arg to as-file. Multiple-arg
versions treat the first argument as parent and subsequent args as
children relative to the parent.
nil
So, it returns java.io.File, which does indeed have member functions .isDirectory and .isFile. Docs for Java classes are very easy to find. And you can also do so via your REPL:
user=> (doc javadoc)
-------------------------
clojure.java.javadoc/javadoc
([class-or-object])
Opens a browser window displaying the javadoc for the argument.
Tries *local-javadocs* first, then *remote-javadocs*.
nil
user=> (javadoc java.io.File)
true
The last executed form opened https://docs.oracle.com/javase/8/docs/api/java/io/File.html in my browser.
Note that above I'm using fully qualified names for Clojure symbols - it works because something else has required the relevant namespace. If the namespace has not been required, you'd have to require it yourself.I recommend https://github.com/babashka/fs for working with files, nicer than in my opinion.
Thanks for your swift and detailed reply! In my inital request I missed mentioning the function .listFiles which I need the return type of. Well, sry to say, I am stupid and still don't get it. In my REPL I tried (doc http://clojure.java.io/file) which is the officlal info which doesn't give me details on members. And (javadoc http://clojure.java.io/file) opens this page with Japanese snippets and no info at all: https://clojure-api-cn.readthedocs.io/en/latest/clojure.java.io/as-file.html So I took the link your system/REPL generated but this is just Javadoc not Clojure. How does the fact that the underlying Java File object's member .listFiles returns File[] help me in Clojure world where the return type seems to be a lazy seq? If you are too busy for this basic and franky stupid beginner's stuff I totally understand you dropping out of this, and I greatly appreciate your time and investment.
@teodorlu i have a look at this!
> which is the officlal info which doesn't give me details on members.
Because c.j.i/file is not an object with members - it's a function that, when you call it properly, returns a java.io.File object. You're interested in that object, not in the function that creates it.
So you need to get javadoc for the File class, not for the file function.
> How does the fact that the underlying Java File object's member .listFiles returns File[] help me in Clojure world where the return type seems to be a lazy seq?
I don't understand the question, could you rephrase it?
Sure. The clojure way of checking docs you gave me (Thanks!) points me to Javadoc. Here I see that the member .listFiles returns File[]. So do I work with File[] now in Clojure world? Well, I don't hitnk so. It's rather a lazy seq or something similar. But where is this documented? I need the precise return type. Knowing the underlying Java object is nice to have but doesn't help my stupid brain to proceed in Clojure world. The call (.listFiles my-file) returns what type?? (Sorry for my possibly comvoluted way of putting things - Suffering from a flu right now.)
Java interop forms return the same thing as their Java equivalents, so you'd indeed get a File[] if that's the case; for how you'd work with it, anything working on seqs works just fine on arrays, and generally Clojure can make sense of a lot of Java objects thrown its way
Does return File[] ?? Oooh, I see. Makes sense. I just vaguely remember that yesterday I saw an error message like "cannot do this on ....LazySeq ..." So I figurered .listFiles returns a lazy seq. MY MISTAKE. Sorry for making a big fuzz about it. Now I need to find out how to Java-interop with a File[] object. THANKS (to all three of you)!
Arrays can be turned into Clojure collections. Or used as is in some contexts. Plus, Clojure has a bunch of functions specifically for arrays.
clojure functions are inner classes of the namespace that creates them:
(ins)user=> (bean )
{:class $file, :requiredArity 2}
(that $ in the middle of the name is how inner classes are represented)
they implement the clojure.lang.IFn interface
(ins)user=> (.invoke ".")
#object[java.io.File 0x79ab34c1 "."]
(ins)user=> (.applyTo '("."))
#object[java.io.File 0x28d79cba "."]
as mentioned up thread, it returns a java.io.File object
(ins)user=> (bean ( "."))
{:path ".", :freeSpace 521537241088, :parent nil, :directory true, :parentFile nil, :name ".", :file false, :canonicalFile #object[java.io.File 0x736f3e9e "/Users/justin"], :absolute false, :absoluteFile #object[java.io.File 0xbdc8014 "/Users/justin/."], :hidden true, :class java.io.File, :canonicalPath "/Users/justin", :usableSpace 521537241088, :totalSpace 994662584320, :absolutePath "/Users/justin/."}
(bean is useful for getting a hint of what's in an object but usually not useful in real code)