Re: String representation of an Eclipse Term

From: <RolWenzel_at_aol.com>
Date: Thu 13 Dec 2001 09:02:24 PM GMT
Message-ID: <12a.905f731.294a7161@aol.com>
RE: [eclipse-users] String representation of an Eclipse TermJosh, thank you
for your fast response.

Your solution works fine, besides the fact that it is "translating"
variables to their internal representation (for example "_1891").
"term2String(foo(X, Y), myString)." will result in myString = "foo(_181,
_176)" instead of "foo(X, Y)".
Is there any possibility to fix that?

Thanks for your support,
Roland Wenzel

  ----- Original Message -----
  From: josh singer
  To: 'RolWenzel@aol.com'
  Sent: Friday, December 14, 2001 6:54 AM
  Subject: RE: [eclipse-users] String representation of an Eclipse Term


  Hi Roland,

  I'm glad you asked this question. We deliberately changed the behaviour of
toString() as it was misleading a lot of developers. The trouble is that
java does not know enough about the ECLiPSe term to produce from it a string
which is both human-readable and reliably ECLiPSe-readable.

  The best way to convert a term to a string so that it has these properties
is to use the writeq/2 predicate on the ECLiPSe side, i.e. something like

  term2String(YourTerm, YourString):-
    open(string(""), update, StringStream),
    writeq(StringStream, YourTerm),
    get_stream_info(StringStream, name, YourString),
    close(StringStream).

  tempest: eclipse -b test.pl
  ECLiPSe Constraint Logic Programming System [kernel]
  Copyright Imperial College London and ICL
  Certain libraries copyright Parc Technologies Ltd
  GMP library copyright Free Software Foundation
  Version 5.3 #41, Sat Nov 24 13:49 2001
  [eclipse 1]:  term2String('_yarg'(snoll, "grotch", 4+5), String).

  String = "'_yarg'(snoll, \"grotch\", 4 + 5)"
  Yes (0.00s cpu)
  [eclipse 2]:

  We considered putting something in the Java interface which would have
been a wrapper for the writeq/2 builtin, but decided against it.

  BTW I think the use of writeq/2 instead of toString() was hinted at in the
release notes page "Changes to the Java-ECLiPSe Interface, v5.2 to v5.3".

  hope this helps.

  josh

  Developer, Parc Technologies Limited
  josh.singer@parc-technologies.com
  http://www.parc-technologies.com

  This e-mail message is for the sole use of the intended recipient(s)
  -its contents are the property of Parc Technologies Limited (or its
  licensors) and are confidential. Please do not copy, review, use
  (except for the intended purposes), disclose or distribute the e-mail
  or its contents (or allow anyone else to do so) without our prior
  permission. Parc Technologies Limited does not guarantee that this
  e-mail has not been intercepted and amended nor that it is
  virus-free. You should carry out your own virus checks before opening
  any attachment.  Any opinions expressed in this e-mail message are
  those of the author and not necessarily Parc Technologies Limited.



  -----Original Message-----
  From: RolWenzel@aol.com [>mailto:RolWenzel@aol.com]
  Sent: Thursday, December 13, 2001 4:27 PM
  To: eclipse-users@icparc.ic.ac.uk
  Subject: [eclipse-users] String representation of an Eclipse Term



  Hi,

  I have a problem getting the correct string representation of an Eclipse
  Term since I upgraded to the version 5.3 of Eclipse.

  In Version 5.2, eclipse_to_java_formatted.readTerm().toString() provided
the
  correct string representation, for example "foo (X, a).".
  In Version 5.3, you will get an object containing the Eclipse-classes, for
  instance "class com.parctechnologies.eclipse.CompoundTermImpl" with a
  functor, the arity and so on.

  Trying to create the "nicer" string out of the Object, I wrote the
function
  "getString" that you can find at the end of this mail.
  It works fine, but it doesn't recognize any variables, because they were
  represented as "null" and hence have no "toString" method.
  Simply printing "X" for "null" will result in problems, because foo(X, Y)
  will be printed as foo(X, X).
  Is there another way to translate variables to its original name?
  Or better: is there a build in function in the Java Interface to get the
  string representation from an Eclipse Term, and I just didn't see it?

  Thank you for any hint,
  Roland Wenzel

  ---

   public String getString(Object EclipseTerm)
   {
    String result = "";
    LinkedList LinkList;
    int i;

    if (EclipseTerm == null) {
     return "";
    }

    if (EclipseTerm.getClass().toString().equals("class
  com.parctechnologies.eclipse.CompoundTermImpl")) {
     result = ((CompoundTerm)EclipseTerm).functor();
     if (((CompoundTerm)EclipseTerm).arity() >= 1) {
      result = result + "(";
      for (i=1; i <= ((CompoundTerm)EclipseTerm).arity(); i++) {
       result = result + getString(((CompoundTerm)EclipseTerm).arg(i));
       if (i < ((CompoundTerm)EclipseTerm).arity()) {
        result = result + ", ";
       }
      }
      result = result + ")";
     }
    } else if (EclipseTerm.getClass().toString().equals("class
  com.parctechnologies.eclipse.Atom")) {
     result = result + ((Atom)EclipseTerm).functor().toString();
    } else if (EclipseTerm.getClass().toString().equals("class
  java.util.LinkedList")) {
     result = result + "[";
     LinkList = (LinkedList)EclipseTerm;
     while (!LinkList.isEmpty())
     {
      result = result + getString(LinkList.getFirst());
      LinkList.removeFirst();
      if (!LinkList.isEmpty()) {
       result = result + ", ";
      }
     }
     result = result + "]";
    } else {
     result = result + EclipseTerm.toString();
    }

    return result;
   }
Received on Thu Dec 13 21:03:31 2001

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:12 PM GMT GMT