swirl Guide to OmniMark 6   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
  Related Syntax   Related Concepts  
action   new    

Syntax

  new shelf-name ({string-expression})? insertion-point?
  set new  shelf-name  ({ string-expression})? insertion-point?
           to expression
  where
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 ] [ OMX ] [ ERRORS ]

OmniMark 6.5 Documentation Generated: December 23, 2002 at 6:25:30 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-2002.