imagej - a clojure example

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

imagej - a clojure example

David Pirotte
Hello,

1]

For info, here is the tutorial I used to start to try to use imagej from clojure:

        http://imagej.net/Clojure_Scripting


        [ Note that section 1.1 is obsolate, if you read, start at section 1.2
        [ for a [terribly basic] repl, I do:
        [
        [ java -cp clojure.jar:ij-core.jar:cljs clojure.main
        [
        [ where clj is a symlink to the path of .clj files

Any similar document, even for another library? How to do these things in kawa
would be fantastic for a zero/null java guy like me :), see subsections:

        - You can specify imports in Clojure in a few ways
        - Calling methods and variables on a java object
        - ...
        - Calling static fields and methods: namespace syntax
        - ...
        - Creating objects: invoking constructors

2]

        attached a very first module I should port to kawa, for info as well

        [  I do not ask to do my job here, but any hint(s) to get me me of the ground
        [  more then welcome

        java -cp clojure.jar:ij-core.jar:cljs clojure.main
        Clojure 1.6.0
        user=> (import '(ij IJ)
        '(ij ImagePlus))
        user=> (def bf (ij-open "bf.png"))
        user=> (ij-show bf)
        ...

Cheers,
David

ij_support.clj (7K) Download Attachment
attachment1 (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: imagej - a clojure example

David Pirotte
Heya,

david@capac:~/lpdi/projects/kawa/jars 61 $ ls -ls
total 2076
1944 -rw-rw-r-- 1 david alto 1986620 Sep 24 15:11 ij-1.49v.jar
   0 lrwxrwxrwx 1 david alto      12 Sep 24 15:11 ij.jar -> ij-1.49v.jar
 132 -rw-rw-r-- 1 david alto  132846 Sep 24 15:12 mpicbg_-1.0.1.jar
   0 lrwxrwxrwx 1 david alto      17 Sep 24 15:13 mpicbg.jar -> mpicbg_-1.0.1.jar

david@capac:~/lpdi/projects/kawa/jars 62 $ kawa
#|kawa:1|# (import (ij IJ))
/dev/stdin:1:9: unknown library (ij IJ)
#|kawa:2|#


^^ Of course it is a stupid quizz for someone who knows java, I don't and I don't
want to.  What is the scheme procedure and/or variable, like %load-path in guile,
that I need to set! so that kawa knows where to look for when I do

        (import (ij IJ)) [ if that is correct, I don't know
                                        [ if not please correct me

Also, How do I introspect a module?  Like once yu tll me how to make these
ij-1.49v.jar, mpicbg_-1.0.1.jar, .. known to java, how can I list the public
interface of these modules, its classes, methods ...

Many thanks,
David

attachment0 (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: imagej - a clojure example

Per Bothner


On 09/24/2015 11:30 AM, David Pirotte wrote:

> Heya,
>
> david@capac:~/lpdi/projects/kawa/jars 61 $ ls -ls
> total 2076
> 1944 -rw-rw-r-- 1 david alto 1986620 Sep 24 15:11 ij-1.49v.jar
>     0 lrwxrwxrwx 1 david alto      12 Sep 24 15:11 ij.jar -> ij-1.49v.jar
>   132 -rw-rw-r-- 1 david alto  132846 Sep 24 15:12 mpicbg_-1.0.1.jar
>     0 lrwxrwxrwx 1 david alto      17 Sep 24 15:13 mpicbg.jar -> mpicbg_-1.0.1.jar
>
> david@capac:~/lpdi/projects/kawa/jars 62 $ kawa
> #|kawa:1|# (import (ij IJ))
> /dev/stdin:1:9: unknown library (ij IJ)
> #|kawa:2|#

Is there an actual class ij.IJ in the classpath?  Otherwise what you're doing
won't work.

Try typing ij.IJ directly at the REPL and you should see if it exists.  For example:

#|kawa:5|# java.util.Map
interface java.util.Map
#|kawa:6|#

> ^^ Of course it is a stupid quizz for someone who knows java, I don't and I don't
> want to.  What is the scheme procedure and/or variable, like %load-path in guile,
> that I need to set! so that kawa knows where to look for when I do
>
> (import (ij IJ)) [ if that is correct, I don't know
> [ if not please correct me

You need set the classpath before you start up the Java VM - typically
on the java command line or a CLASSPATH environment variable.
For example:
$ CLASSPATH=.:ij.jar kawa

or:

$ java -cp .:ij.jar kawa.repl

It would be possible for Kawa to use a ClassLoader that can change its
search path on the fly.  I don't think we'd want to do that by default,
because we want to keep Kawa "close to the [JVM] metal".  With a strong use
case we could add it as an optional feature.

> Also, How do I introspect a module?  Like once yu tll me how to make these
> ij-1.49v.jar, mpicbg_-1.0.1.jar, .. known to java, how can I list the public
> interface of these modules, its classes, methods ...

Introspection is a complex feature.  Kawa doesn't really have an introspection
API - you can use the Java reflection API or the model API, but these are nontrivial;
certainly more than a quick reply here.  What is your specific use-case?

If you're just trying the learn what's available in a libray, the usual
method is to look at the javadoc-generated API documentation.  For example
for imagej look here:

http://javadoc.imagej.net/Fiji/overview-summary.html
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: imagej - a clojure example

David Pirotte

> > (import (ij IJ)) [ if that is correct, I don't know
> > [ if not please correct me

> You need set the classpath before you start up the Java VM - typically
> on the java command line or a CLASSPATH environment variable.
> For example:
> $ CLASSPATH=.:ij.jar kawa

Thanks, someone kindly answered on #kawa.  I will mail the example I got so other
may benefit:  I did not know a module was auto define based on the name of the
file... and other things jhope explained me on #irc

> > Also, How do I introspect a module?  Like once yu tll me how to make these
> > ij-1.49v.jar, mpicbg_-1.0.1.jar, .. known to java, how can I list the public
> > interface of these modules, its classes, methods ...

> Introspection is a complex feature.  Kawa doesn't really have an introspection
> API - you can use the Java reflection API or the model API, but these are
> nontrivial; certainly more than a quick reply here.  What is your specific
> use-case?

Everything I can do when using clos I guess.

> If you're just trying the learn what's available in a libray, the usual
> method is to look at the javadoc-generated API documentation.  For example
> for imagej look here:

Sure, but how do you debug?

        Maybe the second jar must be in a specific subdirectory, if that so, how
        would I know?

Cheers,
David

attachment0 (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: imagej - a clojure example

David Pirotte

> > > Also, How do I introspect a module?  Like once yu tll me how to make these
> > > ij-1.49v.jar, mpicbg_-1.0.1.jar, .. known to java, how can I list the public
> > > interface of these modules, its classes, methods ...
>
> > Introspection is a complex feature.  Kawa doesn't really have an introspection
> > API - you can use the Java reflection API or the model API, but these are
> > nontrivial; certainly more than a quick reply here.  What is your specific
> > use-case?
>
> Everything I can do when using clos I guess.
I should have said clos _and_ the module system itself here: I did ask because in
guile we have a substantial amount of procedures related to introspection of modules
themselves, not related to goops [which is itself a separate module, guile's
implementation of clos, not full but almost]:

         I could ask to get the list of public symbols [procedures, variables,
         getters, setters, accessors and methods defined within a module

This said, both jhope and Per pointed me to the command line java commands which
lists the classes of a jar... but that did not help: I still don't know how to debug
this basic situation though, 2 jars, they work when used through Fiji [the imagej
interface], but not using [yet] kawa, neither clojure:  I guess there is something
wrong in the design of imagej, by the way, not in kawa, but I hope java/kawa
experts can help.

I will write another email, time for a new thread, couple of things were solved
today thnks to jhope on irc, but the major problem, which I faced in clojure as
well, unfortunately also occurs when using kawa. But I still have hope to get
through this using kawa.

Cheers,
David

attachment0 (484 bytes) Download Attachment