LFE in Erjang

52 views
Skip to first unread message

dun...@cogitat.io

unread,
Apr 2, 2014, 11:58:44 PM4/2/14
to erj...@googlegroups.com, Robert Virding
(Don't know if Robert is on this list, so cc'ing  him.)

Hey everyone! Just compiled and fired up Erjang for the first time -- was totally inspired by Kresten's talk at Erlang Factory last month... have been dying to get a chance to do this.

Needless to say, I first installed LFE so that I could try it from Erjang. Overall, this was a success. Even called to Java from LFE. Blew my mind.

Okay, so now for some questions ...

An odd artifact crept up after I started the LFE shell:

1> lfe_shell:start().
LFE Shell V5.10.1 (abort with ^G)
> <0.0.569>
2> (+ 1 2 3 4 5)
2> 15


Note the Eshell prompt...

Then, when I executed my next call, the prompt doubled:

2> > 2> (* 2 (+ 1 2 3 4 5 6))
2> 42


Subsequent calls were the same -- no more doubling:

2> > 2> (: lists map (lambda (x) (+ x 2)) (list 1 2 3))
2> (3 4 5)
2> > 2> (: java.io.File createTempFile '"foo" '"bar")
2> #B()


I don't know if this is a problem with lfe_shell, or if there's a better way to start the LFE shell that won't present these artifacts, or if there is a problem with Erjang... I just wanted to bring it up in the hopes that there is a fix for it :-)

Finally, and I suspect this might be a problem with LFE's pretty printer, when I called getProperty, I got a badarg error:

2> > 2> (: java.lang.System getProperty '"java.io.tmpdir")
2> exception error: badarg
  in (: lfe_io_pretty
        print1
       "/var/folders/c8/2cl5l5_102b1qq8bh05t7xw40000gn/T/")
2>
2> > 2>


Overall, I'm pretty excited about the possibilities here... LFE could make an attractive alternative for Clojure folks with the help of Erjang ...

More soon!

d

Kresten Krab Thorup

unread,
Apr 3, 2014, 4:33:06 AM4/3/14
to erj...@googlegroups.com, Robert Virding, dun...@cogitat.io
Maybe you can run LFE with something like

krab$ ../erjang/jerl -pa $LFE_HOME/ebin -noshell -s lfe_shell 
LFE Shell V5.9.3.1 (abort with ^G) 
> (+ 1 2) 


The problem might be that you actually have two shells running (both the LFE one, and the Erlang one).  Now I dunno how that happens or why, but I seem to recall doing something like the above.

Kresten


Mobile: + 45 2343 4626 | Skype: krabtrifork | Twitter: @drkrab
Trifork A/S  |  Margrethepladsen 4  | DK- 8000 Aarhus C |  Phone : +45 8732 8787  |  www.trifork.com

-- 
You received this message because you are subscribed to the Google Groups "Erjang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erjang+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Kresten Krab Thorup

unread,
Apr 3, 2014, 4:38:17 AM4/3/14
to erj...@googlegroups.com, Robert Virding
The second error with calling Java functions… is probably some error in the value mapping. Its a bit complex, and if you want to dive into it I can explain more. But essentially a JavaObject thing can act as more than one kind of erlang term, depending on how you deconstruct it with pattern matching. For Java strings, we keep the string around, wrapped in a synthetic cons cell that will allow you to access head and tail. This is much like how Clojure maps values, but this subsystem is not tested very well. I’d love some help on that.

Kresten

On 03 Apr 2014, at 05:58, <dun...@cogitat.io> <dun...@cogitat.io> wrote:

> Finally, and I suspect this might be a problem with LFE's pretty printer, when I called getProperty, I got abadarg error:
signature.asc

Robert Virding

unread,
Apr 3, 2014, 8:46:03 AM4/3/14
to erj...@googlegroups.com
The first problem is as Kresten said, you are running two shells, the erlang shell and the lfe shell. This is because the lfe_shell:start/0 call spawns a new process running the shell. To just run the shell in the same process use lfe_shell:server/0.

I can't help you with the java side. It will be eaiser to see what is going on with only one shell though. :-)

Robert

Duncan McGreggor

unread,
Apr 3, 2014, 11:59:20 AM4/3/14
to Kresten Krab Thorup, erj...@googlegroups.com, Robert Virding
Worked like a dream :-)

$ LFE_HOME=~/lab/erlang/lfe/ rlwrap ./jlfe

LFE Shell V5.10.1 (abort with ^G)
> (lists:map (lambda (x) (* x x)) '(1 2 3 4 5 6))
(1 4 9 16 25 36)


Thanks to you and Robert for explaining what should have been obvious!

d

Duncan McGreggor

unread,
Apr 3, 2014, 12:10:01 PM4/3/14
to erj...@googlegroups.com, Robert Virding
On Thu, Apr 3, 2014 at 1:38 AM, Kresten Krab Thorup <kr...@trifork.com> wrote:
The second error with calling Java functions… is probably some error in the value mapping.  Its a bit complex, and if you want to dive into it I can explain more.  

I wouldn't mind learning, if you're up for sharing the details...
 
But essentially a JavaObject thing can act as more than one kind of erlang term, depending on how you deconstruct it with pattern matching.  For Java strings, we keep the string around, wrapped in a synthetic cons cell that will allow you to access head and tail.  This is much like how Clojure maps values, but this subsystem is not tested very well.  I’d love some help on that.

As you may have guessed, my knowledge of JVM internals is zero -- I hacked on Java code over 10 years ago for a few months, and over the past couple of years I've worked on a few minor Clojure projects. That is to say I'm not averse to the JVM, but definitely beginner-level. If you can tell me how to help and teach the things I need to know, I'm at your service :-)

I really believe that Java interop with Erlang code bases is of extraordinary benefit (whether that be JInterface, ports, or Erjang) to the larger Erlang community. I find Erjang quite compelling and would love to help give it some love.

Where shall we begin?

d

P.S. With running just the LFE shell, here's the output again from the err'ing call:

> (java.lang.System:getProperty '"java.io.tmpdir")

exception error: badarg
  in (: lfe_io_pretty
        print1
       "/var/folders/_5/7zv364n96xs09vg_7061kvsw0000gn/T/")

>

Duncan McGreggor

unread,
Apr 6, 2014, 6:03:20 PM4/6/14
to erj...@googlegroups.com
I'm hoping to start digging into the LFE/Erjang issues soon. I'll start opening tickets on github for the ones that I find.

I'm getting some basic instructions up here:
  http://lfe.github.io/user-guide/java/erjang/1.html

And I've uncovered another couple issues.

Looking forward to learning more about Erjang :-)

d



On Thu, Apr 3, 2014 at 1:38 AM, Kresten Krab Thorup <kr...@trifork.com> wrote:

Duncan McGreggor

unread,
Apr 6, 2014, 11:02:34 PM4/6/14
to erj...@googlegroups.com, Robert Virding
On Thu, Apr 3, 2014 at 1:38 AM, Kresten Krab Thorup <kr...@trifork.com> wrote:
The second error with calling Java functions… is probably some error in the value mapping.  Its a bit complex, and if you want to dive into it I can explain more.  But essentially a JavaObject thing can act as more than one kind of erlang term, depending on how you deconstruct it with pattern matching.  For Java strings, we keep the string around, wrapped in a synthetic cons cell that will allow you to access head and tail.  

Okay, I'm taking a look at the LFE code right now, and it looks like there's no match for what you've described. I'll try matching a cons and see what that looks like...

[few minutes later]

Got it -- Thanks, Kresten! I've got a match that I'll pass by Robert with a PR to LFE. I'll need his sanity check to see if there's an unanticipated impact elsewhere.

 
This is much like how Clojure maps values, but this subsystem is not tested very well.  I’d love some help on that.

I didn't see anything odd coming from Erjang. Will keep my eyes open, though!

d


Reply all
Reply to author
Forward
0 new messages