set file

action

Syntax
set file string-expression modifier-expression? to string-expression
    


Purpose

Using set with a file expression on the left-hand side is a concise way of creating a file when the entire contents of the file can be described with a single string or a single string source expression. For example,

  define function
     f (value string        file-name,
        value string source input-data)
  as
     set file file-name to input-data
          
is equivalent to
  define function
     f (value string        file-name,
        value string source input-data)
  as
     local stream s
  
     open s as file file-name
     put s input-data
     close s
          
However, the former has the advantage of not requiring the intermediate shelf s.

As a result of this equivalence, set file can use the same modifiers as open.

Related Syntax