RE: String representation of an Eclipse Term

From: josh singer <>
Date: Thu 13 Dec 2001 05:27:56 PM GMT
Message-ID: <0B9686DD2E83D411B67200508B9A9DA255F794@LON-SRV2>
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), 

tempest: eclipse -b
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.


Developer, Parc Technologies Limited

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: []
Sent: Thursday, December 13, 2001 4:27 PM
Subject: [eclipse-users] String representation of an Eclipse Term


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());
    if (!LinkList.isEmpty()) {
     result = result + ", ";
   result = result + "]";
  } else {
   result = result + EclipseTerm.toString();

  return result;
Received on Thu Dec 13 17:27:23 2001

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