File objects?

30 views
Skip to first unread message

Duncan McGreggor

unread,
Apr 6, 2014, 8:29:11 PM4/6/14
to erj...@googlegroups.com
More digging with LFE and Erjang...

When a file object is returned in Java (as appears to be the case with java.io.File.createTempFile), what does Erjang do? I seem to be getting a bitstring data type back:

> (set x (java.io.File:createTempFile '"foo-" '"-bar"))
#B()
> (is_bitstring x)
true

The first line has this equivalent in Erlang:

1> X='java.io.File':createTempFile("foo-", "-bar").
<<>>


I see the temp file being created in the temp directory, with the appropriate prefix and suffix. I can't seem to do anything with the returned data, though (which makes sense, given that it's an empty bitstring). Do you have something in mind for working with files? Or is there something in place already that I should be doing?

Thanks,

d

dun...@cogitat.io

unread,
Apr 10, 2014, 5:43:47 PM4/10/14
to erj...@googlegroups.com
Kresten gave me another tool today, and with it I was able to verify that, even though LFE was seeing the java.io.File object as a bitstring, it really was a java.io.File ;-)

$ cat > java.lfe
(defmodule java)

(defun noop ()
 'noop)
^D


With that created, I was able to do more checking:

$ lfetool repl jlfe
> (c 'java)
#(module java)
> (set tmp-file (java.io.File:createTempFile '"foo-" '"-bar"))
#B()
> (java:call tmp-file 'getClass '() '())
java.io.File


This was a relief :-) I then did some poking. At first I saw the same error we were seeing before... but realizing now that we're actually getting what seem to be proxies to Java objects, I was a bit more adventurous:

> (call tmp-file 'getPath)
exception error: badarg
  in (: lfe_io_pretty
        print1
       "/var/folders/c8/2cl5l5_102b1qq8bh05t7xw40000gn/T/foo-929219021566603233-bar")
> (call (call tmp-file 'isFile) 'toString)
true
> (call (call tmp-file 'getPath) 'length)
76


The two others I tried (getBytes and toCharArray) returned errors similar to what Robert and I were seeing while debugging the past few days.

Thanks, and I hope to have more to report to you with regard to the string issues with LFE+Erjang.

d

Kresten Krab Thorup

unread,
Apr 11, 2014, 2:31:56 AM4/11/14
to erj...@googlegroups.com
This is the proxy object.

https://github.com/trifork/erjang/blob/master/src/main/java/erjang/m/java/JavaObject.java

You can see that a java object may be responding true to multiple is_xxx functions. Eg a String can be both a list, an atom and a binary.

Kresten

Sent from my iPhone
--
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<mailto:erjang+un...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

rvirding

unread,
Apr 12, 2014, 12:58:35 PM4/12/14
to erj...@googlegroups.com
Hmm. Does that mean that for example I can do basic list, atom and binary operations on a String? I mean can I trust the type test so if it says atom then I can do atom stuff on it?

On a more general level is that good? Couldn't lead to the strange case where in Erlang they test equal but also test as different types?

Robert


On Friday, April 11, 2014 8:31:56 AM UTC+2, Kresten Krab Thorup wrote:
This is the proxy object.

https://github.com/trifork/erjang/blob/master/src/main/java/erjang/m/java/JavaObject.java

You can see that a java object may be responding true to multiple is_xxx functions. Eg a String can be both a list, an atom and a binary.

Kresten

Sent from my iPhone

To unsubscribe from this group and stop receiving emails from it, send an email to erjang+un...@googlegroups.com<mailto:erjang+unsub...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages