Previous SectionLibraries
Document HomeContents
OVM StreamsNext Section

Scope and Persistence of Variables / Constants

Variable / Constant Scope

In OVM variables (and constants) do not have to share a single global scope as they do in Ozterm. This allows variable names to be reused where convenient.

Consider the following example.

@integer fred = 10           ! define a global variable fred and set to 10
@comment("fred = ",fred)     ! display the value of the global fred

@begin                       ! start a new scope
    @string fred = "Hello"   ! define a local variable fred
    @comment("fred = ",fred) ! display the value of the local fred
@end                         ! end of the new scope

@comment("fred = ",fred)     ! display the value of the global fred

The first definition of fred has file or global scope (I.e. fred is available for use throughout the file). The second definition has local scope, and is not accessible after the @end command is reached.

Note. All session variables (variable substitution variables) share global scope, and are also available between files opened within the same session.

Persistance of Variables

All variables / parameters in OVM are static (ie Only a single copy of a variable exists throughout program execution). This means that the variable’s value is not lost when it goes out of scope - ie execution has left the command block the variable was defined in. This is unlike most 3GL’s where a variable’s value is lost when it goes out of scope.

Consider the following example.

@procedure proc1()
@begin
    @integer fred              ! initially fred's value will be 0
    @set fred = fred + 1       ! increment fred's value by 1
    @comment("fred = ",fred)   ! display fred's value
@end

! Now call the procedure proc1 3 times
@proc1                         ! will display fred = 1
@proc1                         ! will display fred = 2
@proc1                         ! will display fred = 3

In this example it should become clear that the previous value of fred has been remembered between calls to the procedure proc1.

A side effect of variable persistance is that recursion (where a function or procedure calls itself) will probably not work as desired as the recursive calls will interfere with each other. This also applies to the parameters of user defined procedures and functions.



Previous SectionLibraries
Document HomeContents
Working with OVM StreamsNext Section



This publication has been prepared and written by Telstra Corporation Limited (ACN 051 775 556), and is copyright. Other than for the purposes of and subject to the conditions prescribed under the Copyright Act, no part of it may in any form or by any means (electronic, mechanical, microcopying, photocopying, recording or otherwise) be reproduced, stored in a retrieval system or transmitted without prior written permission from the document controller. Product or company names are trademarks or registered trademarks of their respective holders.

Note for non-Telstra readers: The contents of this publication are subject to change without notice. All efforts have been made to ensure the accuracy of this publication. Notwithstanding, Telstra Corporation Limited does not assume responsibility for any errors nor for any consequences arising from any errors in this publication.