> I thought it might be fun to try out the new repl-utils expression-info fn > on > this.
Is this just in source control, or is it in a release? I'm using 1.0.0, and I don't seem to have that function. > So first I had to recreate your 'import' line (you might consider including > this > kind of detail next time you post a question): Yeah, sorry about that. I'll remember next time. > Well, that seems to have done it. Using that style in the original > expression, > we get: > > (defn searcher-path [#^IndexSearcher searcher] > (let [#^FSDirectory fsdir (.. searcher getIndexReader directory) > #^String path (.. fsdir getFile getPath)] > path)) > > That compiles without reflection warnings. I thought I had tried this and gotten an error for it; I must have made a typo and assumed it was an invalid thing to do. It's certainly working now :) Where can I get more info on the expression-info call? A google search for "expression-info" and clojure gives a pdf on multiple dispatch and nothing else. > Note also that hinting 'path' as 'String' doesn't really do any good when > all we > do is return it: That's really strange. The clojure compiler doesn't put types on functions when the only value returned from a function has an explicit type? > user=> (expression-info '(searcher-path nil)) > nil > > If you want to promise that 'searcher-path' will always return a String so > that > the compiler can make further type deductions based on that, you need to > hint > the function itself: > > (defn #^String searcher-path [#^IndexSearcher searcher] > (let [#^FSDirectory fsdir (.. searcher getIndexReader directory)] > (.. fsdir getFile getPath))) > > user=> (expression-info '(searcher-path nil)) > {:class java.lang.String, :primitive? false} In the type hinting page, it says type hits can be applied to function parameters, let-bound names, var names and expressions. Is the #^String here being applied to a var name (searcher-path)? It wasn't obvious to me that one could do that, although I guess functions names are variables just like any other names in the system. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---