swirl
Guide to OmniMark 7   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
  Related Syntax   Related Concepts  
action  

new

 
 

Syntax

  new shelf-name ({string-expression})? insertion-point?
  set new  shelf-name  ({ string-expression})? insertion-point?
           to expression

Argument definitions

insertion-point
A phrase describing where in the shelf the new item should be inserted. The insertion point is identified using the keywords before or after. If no insertion point is specified, the item is placed in the last position on the shelf.


Purpose

new inserts a new item onto a shelf and can only be invoked on shelves that have been declared variable:

  local integer x variable initial-size 0
  new x

By default, the new item is inserted after the last item on the shelf. You can insert the new item before or after another item:

  new x{"wilma"} after [2] 

To make the new item the first item on the shelf, you can use before [1] or after [0].

A new item can be given a key as it is inserted:

  new x{"fred"} before {"barney"}
  new x{"wilma"} after [2] 

The set new action combines the new and set actions into one action so that

  new x{"fred"} before [1]
  set x{"fred"} to "flintstone0"
can be replaced with:
  set new x{"fred"} before [1] to "flintstone0"

Putting these code fragments together gives us the following program:

  process
     local stream x variable initial-size 0
     new x
     set key of x to "barney"
     set x to "flintstone1"
     set new x{"fred"} before [1] to "flintstone0"
     set x{"fred"} to "flintstone0"
     new x{"wilma"} after [2]
     set x{"wilma"} to "flintstone2"
     repeat over x
            output x || " has key " || key of x || "%n"
     again
  ; Output: "flintstone0 has key fred
  ;          flintstone1 has key barney
  ;          flintstone2 has key wilma"

    Related Syntax
   set
 
Related Concepts
   Shelves
   Variables
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACYLIBRARIES ] [ ERRORS ]

OmniMark 7.1.2 Documentation Generated: June 28, 2005 at 5:45:34 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © Stilo Corporation, 1988-2005.