String: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (→‎External links: WP link style)
m (Text replacement - "<source" to "<syntaxhighlight")
Tags: Mobile edit Mobile web edit
Line 2: Line 2:
|<code><nowiki>'abc'</nowiki></code>
|<code><nowiki>'abc'</nowiki></code>
|}
|}
In APL, a '''string''' is a [[vector]] of [[character]]s. Strings are written using single quotes, for example <source lang=apl inline>'string'</source>.
In APL, a '''string''' is a [[vector]] of [[character]]s. Strings are written using single quotes, for example <syntaxhighlight lang=apl inline>'string'</source>.


A single character in quotes, such as <source lang=apl inline>'a'</source>, creates a [[scalar]] character rather than a string. To create a [[singleton]] string the [[ravel]] function is typically used, as in <source lang=apl inline>,'a'</source>. Ravelling a quoted literal always produces a string. This consideration only applies to exactly one character (or two quotes representing a single character, as described in the next paragraph); quotes with no characters between them (<source lang=apl inline>''</source>) form an [[empty]] string.
A single character in quotes, such as <syntaxhighlight lang=apl inline>'a'</source>, creates a [[scalar]] character rather than a string. To create a [[singleton]] string the [[ravel]] function is typically used, as in <syntaxhighlight lang=apl inline>,'a'</source>. Ravelling a quoted literal always produces a string. This consideration only applies to exactly one character (or two quotes representing a single character, as described in the next paragraph); quotes with no characters between them (<syntaxhighlight lang=apl inline>''</source>) form an [[empty]] string.


APL's string notation is very simple and includes only one [[wikipedia:Escape sequence|escape]]: two adjacent single quotes within a string stand for one single quote character rather than ending the string and starting a new one. To [[strand]] strings together, put spaces between them. A newline character within a string produces an error. To produce newlines or other non-printing characters which would be inconvenient to include in the source, use an alternative [[character]] creation mechanism, such as [[Unicode Convert]] (<source lang=apl inline>⎕UCS</source>).
APL's string notation is very simple and includes only one [[wikipedia:Escape sequence|escape]]: two adjacent single quotes within a string stand for one single quote character rather than ending the string and starting a new one. To [[strand]] strings together, put spaces between them. A newline character within a string produces an error. To produce newlines or other non-printing characters which would be inconvenient to include in the source, use an alternative [[character]] creation mechanism, such as [[Unicode Convert]] (<syntaxhighlight lang=apl inline>⎕UCS</source>).


Some users of [[Nested array model|nested]] APLs have proposed a dedicated [[string datatype]] to allow strings to be manipulated as a single entity, and in particular, to allow them to be compared with [[scalar function]]s. In [[Flat array model|flat]] APLs these problems are not felt so strongly because [[box]]ed arrays behave more like a simple datatype.
Some users of [[Nested array model|nested]] APLs have proposed a dedicated [[string datatype]] to allow strings to be manipulated as a single entity, and in particular, to allow them to be compared with [[scalar function]]s. In [[Flat array model|flat]] APLs these problems are not felt so strongly because [[box]]ed arrays behave more like a simple datatype.

Revision as of 10:34, 11 September 2022

'abc'

In APL, a string is a vector of characters. Strings are written using single quotes, for example <syntaxhighlight lang=apl inline>'string'</source>.

A single character in quotes, such as <syntaxhighlight lang=apl inline>'a'</source>, creates a scalar character rather than a string. To create a singleton string the ravel function is typically used, as in <syntaxhighlight lang=apl inline>,'a'</source>. Ravelling a quoted literal always produces a string. This consideration only applies to exactly one character (or two quotes representing a single character, as described in the next paragraph); quotes with no characters between them (<syntaxhighlight lang=apl inline></source>) form an empty string.

APL's string notation is very simple and includes only one escape: two adjacent single quotes within a string stand for one single quote character rather than ending the string and starting a new one. To strand strings together, put spaces between them. A newline character within a string produces an error. To produce newlines or other non-printing characters which would be inconvenient to include in the source, use an alternative character creation mechanism, such as Unicode Convert (<syntaxhighlight lang=apl inline>⎕UCS</source>).

Some users of nested APLs have proposed a dedicated string datatype to allow strings to be manipulated as a single entity, and in particular, to allow them to be compared with scalar functions. In flat APLs these problems are not felt so strongly because boxed arrays behave more like a simple datatype.

External links

APL features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell search
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR