Tail recursion elimination implemented on Shen on Java

96 views
Skip to first unread message

jo...@mentics.com

unread,
Dec 6, 2012, 10:43:53 PM12/6/12
to qil...@googlegroups.com
Now you can self-tail-recurse all you want with no extra stack use! It
gets converted at compile time to a loop.

The new version is up at the same permalink:
http://www.mentics.com/files/shen/shen-on-java.zip

If you run into bugs, we can discuss them here, or if you prefer, you
can submit a bug report here:
https://www.assembla.com/spaces/shen-on-java/tickets/new


I don't know if I caught every case, but this works:

(define test
0 -> "done"
X -> (test (- X 1)))

(test 100000)

jo...@mentics.com

unread,
Dec 10, 2012, 3:28:55 AM12/10/12
to Artella Coding, qil...@googlegroups.com
They could be combined. Unfortunately, Java doesn't have a way to
embed jars inside other jars--which is rather frustrating. Exploding
and creating an uber-jar would be the way to do it. If the community
would prefer that, I could package it that way.

Perhaps I'll work on that. Then it could be an executable jar without
any need for a batch/shell script at all.


On Sun, Dec 9, 2012 at 3:28 AM, Artella Coding
<artella...@googlemail.com> wrote:
> Hi Joel, just out of curiosity what is the reason for keeping the
> kryo-debug-2.20-all.jar and shen-on-java-0.6.0.jar seperate? i.e. is it
> possible to merge these into one? [p.s. I am not requesting this since I
> managed to get shen java up and running fine, but I am just curious to know
> if this can be done]. Thanks

jo...@mentics.com

unread,
Dec 10, 2012, 4:02:01 AM12/10/12
to Artella Coding, qil...@googlegroups.com
On Sun, Dec 9, 2012 at 11:37 AM, Artella Coding
<artella...@googlemail.com> wrote:
> Yes, thanks for this. Just tried it out on the tail recursive code in
> https://groups.google.com/d/msg/qilang/d6FUR_RDJI8/u8M88zJq8O8J and it gives
> same number. It is also faster :

How are you timing this? Are you using the time function?
(time (totalPrimes 20000))


On Sun, Dec 9, 2012 at 3:43 PM, Artella Coding
<artella...@googlemail.com> wrote:
> should be approaching this speed, though I am not sure since I dont know how
> differently numbers in Shen are represented as compared to Java (see

Based on Willi's enlightening email, it appears I perhaps
misunderstood the spec regarding numbers so I think I'll go change it
to strictly use Double's and see what happens.

I had thought that the spec required differentiating between integers
and floats, but apparently that is not the case. Rather, it appears
that when the spec says:

"Numbers are either integers or floats;"

all it means is that for some numbers, integer? will return true and
it is not a requirement about the implementation.

jo...@mentics.com

unread,
Dec 10, 2012, 11:45:40 AM12/10/12
to Marko Kocić, qil...@googlegroups.com, Artella Coding
On Mon, Dec 10, 2012 at 8:04 AM, Marko Kocić <ma...@euptera.com> wrote:
> Actually, you can embed jar inside jar in Java just fine. The problem you
> have is probably how to add that inside jar to classpath.

Right, that's what I meant.


> What you can do is create a new URLCassLoader used to bootstrap repl, and
> add inner jars to it using "outer.jar!/inner.jar" as a URL, since Java can
> reference file inside a Zip directly, and Jar is just a zip. I used this
> approach back in the past, and it worked in basic case, though I had
> problems when using signed jar inside signed jar in this way.
> I'm not sure if commandline classpath allows you to reference inside jars
> this way though.

Right, there's even a project to make it easier for you:
http://one-jar.sourceforge.net/

I'd just rather not go that route at this point.
Reply all
Reply to author
Forward
0 new messages