contentsconceptssyntaxlibrariessampleserrorsindex
Full text search
Binding shelf instances with "using"  
 

Introduction

The meanings of using and save are made a bit more complex by this example. The example illustrates some atypical aspects of shelf usage, which typically do not occur in a well-organized program.

The question is, when an "A" is found in the input, what is the value of counter "c" written to #process-output? Is it 7, 25, or 26? The answer is 25.

The answer is based on the following rule: a shelf or attribute bound by a using prefix, or by a modifiable or read-only function argument, refers to the"version" of the shelf or attribute that existed at the point that the using prefix was performed or the function was called. This occurs independently of what may have happened within the action following the using prefix or the local scope body of the called function.

In this example, within the using prefix, "c" refers to the shelf as it was at the point of using, even though put caused the shelf to be saved and a new instance of the shelf created. The saved shelf is what is incremented (to 7). However, the put outside of the using prefix refers to the current "version" of the shelf "c", which is the one created by the save-clear of the element rule (the one triggered by the put action performed on the #markup-parser stream).



Sample

  context-translate

  global counter c variable initial-size 1

  element #implied
     save-clear c
     set new c to 25
     output "%c"

  find "A"
     using c @ 1
     do
        set c to 6
        put #markup-parser "<x>xxx"
        increment c
     done
     put #process-output "c = %d(c)%n"

   
----  

Top [CONTENTS] [CONCEPTS] [SYNTAX] [LIBRARIES] [SAMPLES] [ERRORS] [INDEX]

Generated: April 21, 1999 at 2:01:41 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-1999.