Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Wednesday January 19, 2005
09:45 PM

Begging for Java help :)

[ #22796 ]

There may not be much Perl content here, but this really is about Perl. I've ported virtually all of this to Perl, right down to the bugs.

As it turns out, my predicate logic code will do the first unification but fails to handle successive unifications. It could be something silly. It could be something profound. I have no idea which.

At first I worked out all of the bugs by carefully stepping through the Java and Perl code side by side, but this particular bug is one that I have in the Java code, too. What's even more irritating is that the Java applet does not have this bug. It's only when I remove it from the applet and try to run it as a stand alone application do things fail. So I have two piece of Java code that should report the same results, but don't and I have no idea why. I'm stumped.

If anyone thinks they find the bug, here's what I have done (twice!). Download the source and strip out the applet code. Then strip it down until you can run the following code:

import java.util.*;

public class Append {
    public static Term        query;
    public static ParseString p;
    public static Engine      eng;

    public static void main(String[] args) {
        try {
            p     = new ParseString("append(X,Y,[a,b,c,d]).");
            query = new Term(p);
        } catch (Exception f) {
            System.out.println("Can't parse query!");
        }
        if (query != null) {
            try {
                eng = new Engine(query,
                    ParseString.consult(
                        "append([],X,X)."
                      + "append([W|X],Y,[W|Z]) :- append(X,Y,Z).",
                        new Hashtable()
                        // the final argument is no longer required
                    )
                );
                eng.start(); // prints first result
                eng.more();  // prints 'No.'
            } catch (Exception f) {
                System.out.println("Can't parse program!");
            }
        }
    }
}

What's really strange is the result of engine.more() prints before the result of engine.start(). I suppose that's a hint, but I still can't figure it out.

As for the applet, click the "append" button and enter append(X,Y,[a,b,c,d]) in the query box. When you click Run Query, it will give the same results as eng.start(), but when you click More? button it keeps returning results until there are no more results.

In fact, just to make it easy, I even have a downloadable version of mine. Just compile and run it.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • At first glance, it seems related to the fact that the Engine class extends Thread. As I understand it, your main() method calls more() even though start() may not have finished yet.

    I guess this is not happenning in the Applet since the more() button is handled by a button.

    --
    -- briac
    • As it turns out, this was the problem. Someone over on Live Journal pointed out the issue and the exact spot where the problem was occurring and I fixed it and uploaded a new version. Now I just need to find out why my Perl version is failing :(