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
()
| 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 |