メインコンテンツまでスキップ
バージョン:25.2

asText

  • function, special function message / property of objects
  • The text or asTextfunction returns a text representation of any value
  • The asText() function (and synonymous as text operator) will also force SenseTalk to perform textual comparisons between values. Normally, if two values can be treated as numbers, SenseTalk will compare them numerically. The as text operator (applied to either value) will override this behavior:
         put "007" is equal to "7.0" -- true
put "007" is equal to "7.0" as text -- false
put "007".asText is equal to "7.0" -- false
  • When the asText function is called for an object or property list, several steps are taken to determine the text representation to use for the object.
    • First, an asText message is sent to the object. If the object has a ‘to’ or ‘function’ handler for this message, that handler is called and its return value is used as the text representation for the object. This allows an object to provide custom behavior to provide a useful description for the object.
    • If the object doesn’t handle the asText message but has an asText property, the value of the asText property is used as the text representation of the object.
    • If the object doesn’t handle the asText message and has no asText property, but it does have an asTextFormat property, the value of that property is used as a merge template. The merge function is called with that template, in the context of the object (so expressions using ‘me’ and ‘my’ within the template will refer to the object). The merged value is then used as the text representation of the object.
    • If the propertyListFormat’s asTextEnabled property is set to False, none of these mechanisms are used. In this case, or if none of the earlier steps results in a value, the propertyListFormat’s other properties are used to create a text representation using the keys and values of the object’s properties.
  • Related: the propertyListFormat