Re: AOT compilation and calling Clojure from Java

2010-08-16 Thread sebastien
Yes, it helped! Thank you!

To make the story complete I put here complete code:

semantic/hello.clj:

(ns semantic.hello
  (:gen-class
   :name semantic.hello
   :methods [[sayhello [] void]
  [sayhello_arg [String] void]]))

(defn -sayhello [this] (println "Hello from Clojure!"))

(defn -sayhello_arg [this arg] (println (str "Hello " arg "!")))


project.clj:

(defproject google-groups-option "1.0.0-SNAPSHOT"
  :description "FIXME: write"
  :dependencies [[org.clojure/clojure "1.2.0-beta1"]
 [org.clojure/clojure-contrib "1.2.0-beta1"]]
  :namespaces [semantic.hello])


Test.java:

import semantic.hello;

class Test {
public static void main(String[] args) {
semantic.hello h = new semantic.hello();
h.sayhello();
h.sayhello_arg("Fred");
}
}

Though my eclipse still shows errors while editing, it CAN compile and
run this code without problems.

-- 
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


Re: AOT compilation and calling Clojure from Java

2010-08-16 Thread Wilson MacGyver
you'd import semantic.hello

then in your java code, you
would first create it by doing new semantic.hello()

then you can call it form java by doing
.sayhello() without the -

you also need to define your sayhello differently I think.

it needs to be  (defn -sayhello [this] (println "Hello from
clojure!")) Only -main doesn't need
"this"

On Sun, Aug 15, 2010 at 12:04 PM, sebastien  wrote:
> I understand that after AOT compilation Clojure namespaces and
> functions became completely normal Java classes and can be called from
> any Java code, is it correct? If so, how will look like this call? For
> example, I have clojure module:
>
> (ns semantic.hello
>  (:gen-class))
>
> (defn -sayhello [] (println "Hello from clojure!"))
>
> (defn -main [] (-sayhello))
>
> and I want to call function -sayhello from Java program:
>
> import ???
>
> class Test {
>
>    public static void main(String[] args) {
>         ???
>    }
>
> }
>
> What should I write instead of ??? signs?
>
> I know that the answer is easy, but it seems like I'm missing
> something all the time.

-- 
Omnem crede diem tibi diluxisse supremum.

-- 
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


Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread Meikel Brandmeyer
Hi,

On 15 Aug., 21:41, sebastien  wrote:

> Unfortunetly it doesn't work, pointing to h.hello() and saying "cannot
> find symbol".
>
> Any suggestions?

First the method is called sayhello. Not just hello. Then you have to
declare the method in the gen-class clause.

(ns semantic.hello
  (:gen-class
:methods [[sayHello [] void]]))

More on http://clojure.org/compilation and in the docs for gen-class
http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/gen-class.

Hope this helps.

Sincerely
Meikel

-- 
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


Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien
I tried to compile hello.clj with "lein compile" and with "(compile
'semantic.hello)", and also with old versions of clojure.jar and
clojure.contrib.jar (current one is 1.2-beta1), but it all gave the
same result.

-- 
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


Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien

> Can you run:
> javap  YourClass.class

> and give us the result?

Here it is:

public class semantic.hello extends java.lang.Object {
 public static {};
 public semantic.hello();
 public java.lang.Object clone();
 public int hashCode();
 public java.lang.String toString();
 public boolean equals(java.lang.Object);
 public static void main(java.lang.String[]);
}

It seems like compiled class has no methods, though they are compiled
as an inner classes (I can see them in classes directory).
I also added several methods:

(defn -sayhello [] (println "Hello from clojure!"))

(defn sayhello2 [] (println "Hello from clojure!"))

(defn -sayhello-with-args [args] (println (str "Hello" args "!")))

(defn -sayhello-with-args2 [args] (println (str "Hello" args "!")))

But none of them apperead in an output of javap.

-- 
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


Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread Daniel Gagnon
>
>
> Any suggestions?
>
>
Can you run:
javap  YourClass.class

and give us the result?

-- 
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

Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien
Hi Meikel,

Unfortunetly it doesn't work, pointing to h.hello() and saying "cannot
find symbol".
   ^
Same with my Eclipse, which says that import "semantic" cannot be
resolved, though both package and class are in the bin (classes)
directory.

Any suggestions?

-- 
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


Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread Meikel Brandmeyer
Hi,

Am 15.08.2010 um 18:04 schrieb sebastien:

> I understand that after AOT compilation Clojure namespaces and
> functions became completely normal Java classes and can be called from
> any Java code, is it correct? If so, how will look like this call? For
> example, I have clojure module:
> 
> (ns semantic.hello
>  (:gen-class))
> 
> (defn -sayhello [] (println "Hello from clojure!"))
> 
> (defn -main [] (-sayhello))
> 
> and I want to call function -sayhello from Java program:

import semantic.hello;

> class Test {
> 
>public static void main(String[] args) {
semantic.hello h = new semantic.hello();

h.sayhello();
>}
> 
> }
> 
> What should I write instead of ??? signs?
> 
> I know that the answer is easy, but it seems like I'm missing
> something all the time.

Sincerely
Meikel

-- 
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


AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien
I understand that after AOT compilation Clojure namespaces and
functions became completely normal Java classes and can be called from
any Java code, is it correct? If so, how will look like this call? For
example, I have clojure module:

(ns semantic.hello
  (:gen-class))

(defn -sayhello [] (println "Hello from clojure!"))

(defn -main [] (-sayhello))

and I want to call function -sayhello from Java program:

import ???

class Test {

public static void main(String[] args) {
 ???
}

}

What should I write instead of ??? signs?

I know that the answer is easy, but it seems like I'm missing
something all the time.

-- 
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