String

From the SETL Wiki

Jump to: navigation, search

string is one of the built-in primitive types in SETL. It represents a string of arbitrary length. It can be used for encoded text strings or binary data.

Strings represent bytes rather than characters. There are no built-in character encoding, decoding or conversion functions in SETL. Applications must provide their own encoding and decoding if necessary.

There is no separate "byte" or "character" type. Addressing a single byte within a string yields another string containing a single byte.

Some of the documentation still refers to bytes within a string as "characters". This is only accurate when using a single-byte encoding such as ASCII or Latin-1.

[edit] Basic operations on strings

If s is a valid string then:

  • #s returns the length of s in characters, as an integer.
  • s * n (or equivalently n * s), where n is a non-negative integer, returns a string consisting of s repeated n times, e.g. 'abc' * 2 gives 'abcabc'.
  • abs s (and in GNU SETL, also ichar s), where s contains exactly one byte, returns the numeric value of that byte as an integer.
  • s(i), where i is a positive integer no larger than #s, returns the ith byte of s (indices are numbered starting from 1, as in tuples.) e.g. 'abc'(2) gives 'b'.
  • s(i..j), where i and j are positive integers no larger than #s, returns a string consisting of the ith through jth bytes of s.
  • s + s2, where s2 is another string, returns the concatenation of s with s2, e.g. 'abc' + 'def' gives 'abcdef'.

[edit] string keyword

string is a keyword in CIMS SETL and GNU SETL. It is used only in the data representation sublanguage, to declare variables, bases and/or modes as being constrained to hold only strings.

Personal tools