美文网首页
第六章 ObjectScript - Routine示例

第六章 ObjectScript - Routine示例

作者: Cache技术分享 | 来源:发表于2023-08-22 07:43 被阅读0次

第六章 ObjectScript - Routine示例

Routine示例

下面显示了一个名为 demoroutine 的示例例程,它是用 ObjectScript 编写的。它包含的过程与上一节示例类中所示的方法执行完全相同的操作。

 ; this is demoroutine 
 write "Use one of the following entry points:"
 write !,"random"
 write !,"input"
 write !,"interesting"
 quit 
 
 //this procedure can be called from outside the routine
random() public {
    set rand=$RANDOM(10)+1        ; rand is an integer in the range 1-10
    write "Your random number: "_rand
    set name=$$getnumbername(rand)
    write !, "Name of this number: "_name
 }

 //this procedure can be called from outside the routine
input() public {
    read "Enter a number from 1 to 10: ", input
    set name=$$getnumbername(input)
    write !, "Name of this number: "_name
 }
 
 //this procedure can be called only from within this routine
getnumbername(number) {
    set name=$CASE(number,1:"one",2:"two",3:"three",
        4:"four",5:"five",6:"six",7:"seven",8:"eight",
        9:"nine",10:"ten",:"other")
    quit name
}

 /* write some interesting values
 this procedure can be called from outside the routine
 */
interesting() public {
    write "Today's date: "_$ZDATE($HOROLOG,3)
    write !,"Your installed version: "_$ZVERSION
    write !,"Your username: "_$USERNAME
    write !,"Your security roles: "_$ROLES  
    }

请注意以下要点:

  • 唯一真正以插入符号 (^) 开头的标识符是globals的名称。但是,在运行文本和代码注释中,习惯上引用例程就好像其名称以插入符号开头一样,因为在调用例程时使用插入符号(如本页后面所示)。例如,例程 demoroutine 通常称为 ^demoroutine
  • 例程名称不必包含在例程中。然而,许多程序员将例程名称作为注释包含在例程的开头或作为例程中的第一个标签。
  • 该例程有多个标签:randominputgetnumbernameinteresting

标签用于指示过程(如本示例中所示)、函数和子例程的起点。还可以将它们用作某些命令的目标。

标签在例程中很常见,但也可以在方法中使用它们。

标签也称为入口点或标签。

  • randominput 子例程调用 getnumbername 子例程,该子例程是例程私有的。

我们可以在终端中执行此例程的部分内容,作为演示。首先,下面显示了一个终端会话,我们在其中运行例程本身。

TESTNAMESPACE>do ^demoroutine
Use one of the following entry points:
random
input
TESTNAMESPACE>

当我们运行例程时,我们只是获得帮助信息,如所见。不需要以这种方式编写例程,但这是常见的。请注意,例程在第一个标签之前包含 QUIT,以确保当用户调用例程时,处理在该标签之前停止。这种做法也不是必需的,但也很常见。

接下来,下面显示了几个子例程的行为方式:

TESTNAMESPACE>do input^demoroutine
Enter a number from 1 to 10: 7
Name of this number: seven
TESTNAMESPACE>do interesting^demoroutine
Today's date: 2018-02-06
Your installed version: IRIS for Windows (x86-64) 2018.1 (Build 513U) Fri Jan 26 2018 18:35:11 EST
Your username: _SYSTEM
Your security roles: %All
TESTNAMESPACE>

方法可以包含与例程相同的语句、标签和注释。也就是说,这里有关例程内容的所有信息也适用于方法的内容。

相关文章

  • 2017-12-05

    Daily routine Routine because of the fucking headache, I ...

  • 让生活回到正轨,建立happy routine

    早起有morning routine,护肤有护肤routine,为何不给自己建立一个happy routine,当...

  • 2017-12-03

    Daily Routine Plan Performing actually did: Routine got u...

  • 最近颇受触动的几个单词

    Routine 常规,惯例 They found relief in their routine. 周六的晚上读到...

  • Routine

    每天的路

  • ROUTINE

    今日立夏。因着时差,总是比老友慢了半拍。来温后,每每看着朋友圈中秋了、端午了、过年了…我们总可喘口气,酝酿一下,再...

  • Routine

    早晨6:20起床,洗漱以后7点出门吃饭,7:40到梅岭吹半个小时笛子,然后走到实验室,直到晚上9点才回寝室。 回寝...

  • routine

    最近更新的一些日常惯例。 不再把每一天都按照相同的情况安排,毕竟每一天都是不同的,尤其是周中之后精力迅速下滑,需要...

  • routine

    每天十五分钟的写作+15分钟的打坐?‍♂️

  • Routine

    题:Routine,有道词典,日常工作,例行公事之意。 全家新出了三款冰淇凌,新的有这么多,大概是我太不常去的缘故...

网友评论

      本文标题:第六章 ObjectScript - Routine示例

      本文链接:https://www.haomeiwen.com/subject/mbaymdtx.html