HP3000-L Archives

April 1997, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Jeff Vance <[log in to unmask]>
Reply To:
Jeff Vance <[log in to unmask]>
Date:
Fri, 4 Apr 1997 23:02:39 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (65 lines)
On Apr 4,  8:47pm, Steve BARRETT wrote:
> Subject: CI Variable Names & Brackets
> Can anyone explain the use of "brackets" ([]) related to
> dereferencing variables in CI programs?  They solve some problems
> when used to echo variables to the display.  But, I can't seem to
> find any documentation explaining their use in the CI command
> manuals.

This construct may be documented in the Using System Variables Guide ??
As Mark Bixby pointed out, the main purpose of the ![...] construct is
to allow an expression to be embedded into a command line that normally
never expects an expressions.  Eg.
  :build;myfile;disc=![finfo(otherfile,'eof')*2]

lets you create a new file that is twice as large as some other file.  The
BUILD command expects a simple integer for the size of the file, and that is
what the command actually receives as an argument.  Before the BUILD command
is executed, the CI substitutes the result of the expression into the
command line.

![varname] is a simple expression and is completely acceptable.

> Case in point - I defined a variable with a terminal control escape
> sequence to set "return = enter".  When echoed to the terminal using
> explicit dereferencing (echo !varname), the variable was evaluated as
> if it were a numeric expression and gave a division by zero error.
> Placing the variable name in "brackets" (echo ![varname]) solves the
> dereferencing problem.

I, too, would need to see the exact example to give you specific information.
However there is a difference between !varname and ![varname]  Eg:

   :setvar foo "foo!!bar"
   :setvar bar "abc"

   :echo !foo
   fooabc

   :echo ![foo]
   foo!bar

This example reveals that !varname recursively (or dynamically) dereferences
varname; whereas, ![varname] does not.  ![varname] just retrievs the
immediate value of varname, without further evaluation.

I have also used ![varname] in a more complex expression to preserve the
type of varname, since a variable's type is lost as soon as it is explicitly
dereferenced. Another example:

   :setvar foo "bar"
   :setvar bar "xyzzy"
   :echo !foo
   bar                  <--- not what I want
   :echo ![!foo]
   xyzzy

This lets me "recursively" dereference FOO when I know FOO's value contains
the name of another variable, but FOO's value is not dynamic -- ie. no
!varname inside of FOO.

Don't know if this helps much, but its a first stab...
Jeff Vance, CSY

--

ATOM RSS1 RSS2