Top.Mail.Ru
January 19th, 2005 - Java developers — LiveJournal
? ?

Java developers

January 19th, 2005

01:07 pm - merenda - Great eclipse shortcut

Hey all, I just ran across a great eclipse shortcut, thought I would post it. It's equivalent to IntelliJ's "control-F12" shortcut feature:

1 - Open a java file with tons of methods
2 - hit control-o
3 - start typing a method name
4 - Profit! :)

Hope someone finds that helpful.

Take care,
-Frank

07:16 pm - publius_ovidius - Porting from Java to Perl

I've been busy porting to Perl some code that's been written in Java. It's a predicate logic engine (Prolog), In logic-based programming, you may have several results to a query. In the original Java applet code, I have a sample program which generates several results but only generates one result when I remove it from the applet. It could be something silly. It could be something profound. I have no idea which. And this is for a personal project. I am not in school, thus, this is not homework. I think the proper term might be "begging." This code is weird and rather complicated, so this could be a daunting challenge :)

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 code and strip out the applet code until you can run the following code (or just steal mine from the link below):

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!");
            }
        }
    }
}

When you encounter eng.more() in the code above, it merely prints No.. When it's run in the applet, it prints:

Yes: append([a],[b,c,d],[a,b,c,d]).

What's really strange is the result of eng.more() prints before the result of eng.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 (which is the correct behavior.)

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

Powered by LiveJournal.com