|| (concatenation)

operator

Return type: markup source
Returns:        Concatenation of its two arguments.

Syntax
source expression || source expression
    


Purpose

The infix operator || concatenates its two arguments. It can be applied to string, string source, or markup source arguments. The result is a string source if both arguments are of the string or string source type. For example, the expression "Input file: " || file "input.txt" has the type string source. If either argument is a markup source, as in the expression #content || "%n", the result type is markup source.

The || operator consumes its arguments lazily: it starts consuming its second argument only when the first argument is exhausted. This can be important in examples like the following, when the second argument is a string source function:

  define string source function
     generate-instance
  as
     output "<" || #doctype || ">"
         || #main-input
         || "</" || #doctype || ">"
  
  process
     do sgml-parse document scan file "input.dtd" || generate-instance
        output "%c"
     done
          

If the function generate-instance was forced to run before the DTD was parsed, it could not obtain the document type it needs to generate the top-level element.

Another thing to note about this example is that the body of generate-instance consists of a single output action with six || operators. Because the concatenation operator is lazy, this definition behaves the same as the following one with multiple output actions:

  define string source function
     generate-instance
  as
     output "<" || #doctype || ">"
     output #main-input
     output "</" || #doctype || ">"