set new

action

Syntax
set new shelf
   ({string-expression})? insertion-point?
   to (numeric-expression | string-expression | test-expression)


Purpose

The set new action is, essentially, a composition of the set and the new actions. It simply replaces the shelf part of a set action with an entire new action.

The set new action first performs the embedded new action, and then sets the value of the inserted item of the expression after the keyword to.

The type of expression appearing after the keyword to depends on the shelf type:

  • an integer shelf requires a numeric expression
  • a stream shelf requires a string expression
  • a switch shelf requires a test expression

The insertion-point is identified using the keywords before or after.

The following program creates a variable stream shelf, then sets the first value on that shelf. A series of three set new actions is used to create and set the values of new items on that shelf:

  global stream quotes variable initial-size 1
  
  process
     set quotes to "Is this a dagger?"
     set new quotes to "To be or not to be?"
     set new quotes before [2] to "A horse!"
     set new quotes after [1] to "What light?"
     repeat over quotes
        output quotes || "%n"
     again

The output of this program is:

  Is this a dagger?
  What light?
  A horse!
  To be or not to be?

Related Syntax