Converting Objects to Strings

There are now four getters defined in trait Object for converting an Object to a String:

Loading...

In the trait, all of the other methods are defined in terms of asString, so asString is the principal method that you should override when you create a new trait. Frequently, programmers write a method that emits more information about the internal structure of an object to help in debugging. If you do that, make it a getter and call it asDebugString.

asExprString is intended to produce a fortress expression that is equal to the object being converted.

Examples

The automatic conversion to String that takes place when an object is concatenated to a String uses asString.

The assert(a, b, m ...) function uses asDebugString to print a and b when a ≠ b

Here are the results of using the three getters on the same string:

asString:      The word "test" is overused
asExprString:  "The word \"test\" is overused"
asDebugString: BC27/1:
                       J15/0:The word "test"
                       J12/0: is overused

Here they are applied to the range 1:20:2

asString:      [1,3,5,7,... 19]
asExprString:  1:19:2
asDebugString: StridedFullParScalarRange(1,19,2)