MCPcopy Create free account
hub / github.com/SWI-Prolog/packages-jpl / toString

Method toString

src/main/java/org/jpl7/Compound.java:298–316  ·  view source on GitHub ↗

a prefix functional representation of a Compound of the form name(arg1,...), where 'name' is quoted iff necessary (to be valid Prolog source text) and each argument is represented according to its toString() method. Lists are represented depending on JPL.LIST_TOSTRING_TEXTUAL @return string repres

()

Source from the content-addressed store, hash-verified

296 * @return string representation of an Compound
297 */
298 public String toString() {
299 if (isListPair() && JPL.LIST_TOSTRING_TEXTUAL) { // output nice Prolog [.,.,.,.,] format, not prefix format
300 String head_str = arg(1).toString(); // must be at least 1 arg in compound
301 String tail_str;
302 if (arg(2).isListNil()) {
303 return String.format("[%s]", head_str);
304 } else {
305 tail_str = arg(2).toString();
306 StringBuilder builder = new StringBuilder(tail_str);
307 if (arg(2).isListPair()) {
308 builder.deleteCharAt(builder.length()-1); // remove closing ]
309 builder.deleteCharAt(0); // remove opening [
310 }
311 return String.format("[%s, %s]", head_str, builder.toString());
312 }
313 } // just return lists in pre-fix as '[|]'(head, '[|]'(head, '[|]'(head, .....)
314 return JPL.quotedName(name) +
315 (args.length > 0 ? "(" + Term.toString(args) + ")" : "");
316 }
317
318
319

Callers 2

testIsPairList2Method · 0.95
mainMethod · 0.95

Calls 5

isListPairMethod · 0.95
argMethod · 0.95
quotedNameMethod · 0.95
toStringMethod · 0.95
isListNilMethod · 0.45

Tested by 1

testIsPairList2Method · 0.76