Clojure

Discussions regarding Open Source Java projects under z/OS (other than Tomcat)
Post Reply
dba
Posts: 6
Joined: Wed Nov 19, 2008 10:56 am

Clojure

Post by dba » Wed Nov 19, 2008 3:41 pm

By way of introduction, Clojure is a Lisp-1 that runs in a JVM and has the ability to interact with external methods.

At your favorite e.g. Gentoo Linux station, download the zipfile from sourceforge, expand it into a directory, cd to that directory and enjoy a Lispy REPL:

Code: Select all

dba@dba ~/clojure $ java -cp clojure.jar clojure.lang.Repl
Clojure
user=> (print "Hello world!\n")
Hello world!
nil
user=> 
Now: I'm having trouble replicating this quick success in the z/OS world. After tar-ing the clojure directory on my Gentoo box, binary-ftp-ing the tarfile to a z/OS 1.8 system, then untar-ing it, I get the following for my trouble after I ssh into z/OS:

Code: Select all

$ java -cp clojure.jar clojure.lang.Repl
�%?����ヘ�����
This also happens when I specify -Dfile.encoding=iso-8859-1.

Does anybody have a good suggestion on how I can proceed from this point?

dovetail
Site Admin
Posts: 1907
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail » Wed Nov 19, 2008 4:39 pm

Try adding the following arguments:

-Dfile.encoding=ISO8859-1 -Dconsole.encoding=IBM-1047 -Xnoargsconversion

dba
Posts: 6
Joined: Wed Nov 19, 2008 10:56 am

Post by dba » Wed Nov 19, 2008 4:49 pm

Hmm, gets a little farther along.

Code: Select all

$ java -Dfile.encoding=ISO8859-1 -Dconsole.encoding=IBM-1047 -Xnoargsconversion -cp target/clojure-lang-1.0-SNAPSHOT.jar clojure.lang.Repl
Clojure
user=> (+ 1 2)
java.lang.Exception: Unable to resolve symbol: MN in this context (NO_SOURCE_FILE:0)
user=> java.lang.Exception: Unable to resolve symbol: ��� in this context (NO_SOURCE_FILE:0)
user=>
Looks like it's mis-reading the user's console input now.

[Edit: just to clarify, I'm using the svn version]

dovetail
Site Admin
Posts: 1907
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail » Wed Nov 19, 2008 4:58 pm

Are there other files that it uses that you uploaded, or just the jar?

It looks like the output encoding is fine, but now the input encoding is not working. The code is probably doing something odd with how it reads input, making bad assumptions about the codepage being "ASCII". Running with ISO8859-1 as the file encoding usually fixes this, but apparently not in this case. We would probably have to dig into the code to find the problem.

dba
Posts: 6
Joined: Wed Nov 19, 2008 10:56 am

Post by dba » Wed Nov 19, 2008 5:20 pm

Oh no, I uploaded the entire directory. ls -laR results in 1000+ lines, so I imagine you wouldn't want me to post that.

The svn release was downloaded in its entirety, built with maven, perfunctorily (did I just make up a word?) tested on Gentoo, tared and uploaded to z/OS.

Digging into the code, eh? That sounds like an adventure.

dovetail
Site Admin
Posts: 1907
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail » Wed Nov 19, 2008 5:49 pm

When you uploaded the directory, did you leave it in the original codepage (ASCII?) That could be your problem.

You will likely need to leave it in ASCII, since you have set the default file encoding to ISO8859-1.

dba
Posts: 6
Joined: Wed Nov 19, 2008 10:56 am

Post by dba » Thu Nov 20, 2008 8:38 am

I tar-ed the directory, uploaded the tarfile via ftp binary, then untar-ed it. Didn't do any explicit codepage anything!

FWIW, I tried running it within a TSO OMVS session rather than via ssh. The result:

Code: Select all

$ java -Dfile.encoding=ISO8859-1 -Dconsole.encoding=IBM-1047 -Xnoargsconversion -cp target/clojure-lang-1.0-SNAPSHOT.jar clojure.lang.Repl
Clojure                                                                                                                                   
user=>                                                                                                                                    
(+ 1 1)                                                                                                                                   
java.lang.Exception: Unable to resolve symbol: -MN in this context (NO_SOURCE_FILE:0)                                                     
user=> java.lang.Exception: Unable to resolve symbol: � in this context (NO_SOURCE_FILE:0)                                              
user=>

dba
Posts: 6
Joined: Wed Nov 19, 2008 10:56 am

Post by dba » Thu Apr 02, 2009 1:42 pm

Okay, it's working now.

Steve Gilardi (over in the Clojure Google group) tossed me a bone:
The input stream encoding is set on line 175 of src/jvm/clojure/lang/
RT.java . Removing ", UTF8" from the InputStreamReader constructor
would cause Clojure to use the platform's default character set rather
than expect UTF8 or its ASCII subset.

Var.intern(CLOJURE_NS, Symbol.create("*in*"),
- new LineNumberingPushbackReader(new
InputStreamReader(System.in, UTF8)));
+ new LineNumberingPushbackReader(new
InputStreamReader(System.in)));
final static public Var ERR =
And now I have a REPL on z/OS. Thanks for your advice!


Edit: Since Kirk pointed people on ibm-main over to this post, I guess I should mention that the patch above has been incorporated into Clojure, and you shouldn't have to mess with any of the above. Just heat and eat!

Post Reply