ShenDoc 30


 

 

Strings

A string in Shen begins with " and ends with ". The basic functions for strings are 'cn' - which concatenates two strings together, 'pos', which takes a non-negative number N (starting from zero) and returns the Nth unit string of the string and 'tlstr' which returns all of the string apart from its leading unit string. The function 'str' places an atom into a string (effectively enclosing it in quotes).

The action of 'str' within the domain of atoms is as follows (^ is the concatenation sign).

For a symbol S, 'str' returns the string "^S^" that results from enclosing it in quotes.

In earlier versions of Shendoc (< 6.1) the question of the print representation of streams and closures was not determined. In fact these objects are sent to 'str' in the course of printing and hence the print representation of streams and closures depends directly on their string representation under 'str'. In point of fact it is frequently impossible to recover the original expression that evaluated to the stream/closure and so generally their print representation is not readable. In these cases 'str' should use the platform representation unless this is totally confusing.

For a number N, 'str' returns a string "^M^" whose contents M are such that (= M N) is true in Shen. 'str' applied to a large floating point number may return a string whose contents are in e number notation.

For a string S, 'str' returns a string that when printed off reads as "^S^". However the internal representation of the string may and probably will differ from its print representation.

For the failure object, 'str' returns "..."

'str' is not defined for non-atoms. A more general function 'make-string' will place any Shen object into a string, preserving the appearance in a way that makes it conformant to Shen printing conventions (see printing). 'string?' recognises all and only strings.

The $ notation as in ($ hello) is read in by the reader by exploding its argument. ($ hello) is read in as "h" "e" "l" "l" "o"; this was introduced as a convenient shorthand for writing string handling programs.

Shen uses decimal notation for reading bytes and for character codes. The character string "c#67;" will be printed as "C". Note values for n > 127 in 'c#n;" may not be supported by the platform, but the ASCII set (0-127) should be supported.

The function 'n->string' (e.g. '(n->string 45)') maps a code point to the corresponding unit string. The function 'string->n' is the converse. Note values for n > 127 may not be supported by the platform, but the ASCII set (0-127) should be supported.

'intern' maps a string "^S^" to a pseudo-symbol S which may or may not be a symbol. For instance '(intern "true")' returns 'true' which is a boolean; '(intern "123;")' returns '123;' which is not a symbol. Note that where S is a symbol, 'intern' will return a symbol.

Acknowledgements

History
Basic Types in Shen and Kλ
The Primitive Functions of Kλ
The Syntax of Kλ
Notes on the Implementation of Kλ
Boolean Operators
The Syntax of Symbols
The Semantics of Symbols in Shen and Kλ
Packages
Prolog
Shen-YACC
Strings
Strings and Pattern Matching
Lists
Streams
Character Streams and Byte Streams
Bytes and Unicode
Reader Macros
Vectors
Standard Vectors and Pattern Matching
Non-standard Vectors and Tuples
Equality
I/O
Generic Functions
Eval
Type Declarations
External Global Variables
Property Lists and Hashing
Error Handling
Numbers
Floats and Integers
The Timer
Comments
Special Forms

Built by Shen Technology (c) Mark Tarver, September 2021