Arc Forumnew | comments | leaders | submitlogin
Running Java in Arc
3 points by jsgrahamus 4605 days ago | 13 comments
Are there any documents on how to run Java code from Jarc or Rainbow?

Thanks, Steve



2 points by rocketnia 4605 days ago | link

Some ways to call Java from Rainbow are listed here: http://arclanguage.org/item?id=8819

I think the best way to get up to speed with Rainbow is to see it in action (https://github.com/conanite/rainbow/blob/master/src/arc/rain...) and to look at exactly what the selection of JVM-related primitives is (https://github.com/conanite/rainbow/tree/master/src/java/rai...).

A while back, I made a library, jvm.arc, that I find slightly more convenient to use for accessing JVM stuff from Arc, regardless of whether I'm using Rainbow or Jarc (http://rocketnia.wordpress.com/2010/06/01/lathes-arc-to-impl...).

More recently, jazzdev released a version of Jarc that implemented Rainbow's style of JVM access in addition to the Jarc style (http://arclanguage.org/item?id=12684). I cover a lot of corner cases in jvm.arc using reflection, and some of those could probably be implemented in a more direct style now.

One thing to note: Jarc and Rainbow each have their own policies for automatically converting between Arc values and java.util.Maps and such. This is convenient in practice, but it may make some corner-case things impossible without writing custom code in another JVM language like Java. For instance, if a single utility (say, a JSON parser) can return either java.lang.Boolean.FALSE or null, Arc will probably see nil in both cases.

-----

1 point by jsgrahamus 4604 days ago | link

"I think the best way to get up to speed with Rainbow is to see it in action (https://github.com/conanite/rainbow/blob/master/src/arc/rain...)

So I looked at swing.arc and tried copying and pasting it into Jarc:

  Jarc> (java-imports java
    (lang Integer Float)
    (awt Font event.KeyListener))

  (stdin):1: Error: Symbol 'java' has no value

  0:      java
  DEBUG 0:
Does something need to be loaded before executing this?

Thanks, Steve

-----

1 point by varbanov 4602 days ago | link

java-imports is Rainbow specific construct. Jarc doesn't have such function. I guess Jarc doesn't have imports :)

varbanov

-----

2 points by conanite 4602 days ago | link

Rainbow has an implementation of tetris and a text editor, both are full of examples of using swing. What specifically do you want to do?

-----

2 points by varbanov 4605 days ago | link

There's short Jarc documentation on http://jarc.sourceforge.net/ Calling Java from Jarc works nice, as described. I've used this in several occasions.

varbanov

-----

1 point by jsgrahamus 4605 days ago | link

Thanks.

BTW, I found some blog posts about Jarc and tried an example which yielded an error. Any thoughts on this?

  Jarc> (map 'getTime '(list (new java.util.Date)))
  Can't find method: jarc.Symbol.list()
  (stdin):1: Error: Can't apply function: getTime

  0: (map (quote getTime) (quote (list (new java.util.Date))))
  DEBUG 0:

-----

2 points by rocketnia 4605 days ago | link

I think that quote is just a typo. Try (map 'getTime (list (new java.util.Date))).

-----

1 point by jsgrahamus 4604 days ago | link

  Jarc> (map 'getTime (list (new java.util.Date))).
  (stdin):2: Error: Can't apply function: getTime

  0:      (map (quote getTime) (list (new java.util.Date)))
  DEBUG 0: Unknown command: .
  0:      (map (quote getTime) (list (new java.util.Date)))
  DEBUG 0: r 13
  13

  ---

  Jarc> (map 'getTime (list (new java.util.Date)))
  (stdin):4: Error: Can't apply function: getTime

  0:      (map (quote getTime) (list (new java.util.Date)))
  DEBUG 0: r 13
  13

  ---

  Jarc> (map 'getTime (new java.util.Date))
  (stdin):6: Error: Type-error:
  Tue May 15 12:02:40 MDT 2012 is not of type LIST

  0:      (map (quote getTime) (new java.util.Date))
  DEBUG 0: r 13
  13

  ---

  Jarc>

-----

1 point by rocketnia 4604 days ago | link

First error: You included a spurious . at the end. (You caught this.)

Third error: The sequence you passed to 'map was a java.util.Date, not a string or list like 'map expects.

Second error: Now that seems weird.

I can't help much at this time of day, but what happens when you say "(getTime:new java.util.Date)" and "(idfn!getTime:new java.util.Date)"?

-----

1 point by jsgrahamus 4604 days ago | link

  Jarc> (getTime:new java.util.Date)
  1337107797339

  Jarc> (idfn!getTime:new java.util.Date)
  1337107814529

  Jarc>
Thanks.

-----

1 point by rocketnia 4604 days ago | link

Oh, now that we're talking about it, I seem to remember there's some kind of issue where Jarc allows regular function calls on symbols but 'apply on a symbol doesn't work. So how about (apply 'getTime (list:new java.util.Date))?

-----

1 point by jsgrahamus 4604 days ago | link

  Jarc> (apply 'getTime (list:new java.util.Date))
  1337113306091
  Jarc>

-----

2 points by varbanov 4604 days ago | link

I guess there's an issue here because getTime is not a "regular" arc function, but a Java method and the mapping from names to methods is not "hooked" in map implementation (I guess :) ...

Anyway the following works:

Jarc> (map (fn (_) (getTime _)) (list (new java.util.Date)))

(1337177450156)

-----