set

action

Syntax
set name indexer? modifier-expression? to value


set string-sink-function-call to value
    


Purpose

In the first form, set assigns a value to a shelf item; the shelf item's previous value is replaced with the new value.

  import "ombcd.xmd" unprefixed
  
  
  process
     local integer i
     local string  s
     local switch  w
     local bcd     x
  
     set i to 78
     set s to "Hello, World!%n"
     set w to true
  
     set x to 10.56
          

The value appearing on the right-hand side of a set must have the correct type for the shelf item appearing on the left-hand side of the set, or a conversion function must exist that can convert an instance of right-hand side's type to an instance of the left-hand side's type:

  define string conversion-function value switch w
  as
     return w -> "TRUE" | "FALSE"
  
  
  process
     local string s
     local switch w initial { true }
  
     set s to w
          

In the second form, set invokes the given string sink function; within the function invocation, #current-input is initially set to value.

  define string sink function
     hexify (value string sink s)
  as
     using output as s
     repeat scan #current-input
     match any => t
        output "16r2fzd" % binary t
     again
  
  
  process
     set hexify (#main-output) to "Hello, World!%n"
          

When the type of the shelf item on the left-hand side is stream, set is equivalent to an open of the stream, writing to the stream, then a close. For this reason, any modifiers that can be used with open can also be used with set:

  process
     local stream s size 2
  
     set s[1] with referents-allowed defaulting { "" } to "Hello, World!%n"
     set s[2] with referents-displayed                 to s