groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Groff] question regarding PIC and variable scoping


From: Ted Harding
Subject: RE: [Groff] question regarding PIC and variable scoping
Date: Sun, 13 Feb 2000 11:37:28 -0000 (GMT)

On 13-Feb-00 karan bhatia wrote:
> 
> The following generates an error:
> P: [val = 10];
> x = P.val;
> 
> the variable val is defined only within the context of the object named
> P.
> But according to the documentation, variable scoping works like object
> scoping and the above should work fine.  for example, object scoping
> works similarly:
> P: [Q: box]
> x = P.Q.x;
> 
> Is the fact that variables are not accessible outside of the object a
> bug?
> or am i missing some important notation?  Thanks for your time...

"But according to the documentation, variable scoping works like object
scoping" -- according to what documentation?

The original UNIX pic manual says:

  "Names of variables and places within a block are local to that block,
   ... . You can get at the internal place names [set with a label like A:
   within the block] with constructs like last [].A or B.A where B is a
   name attached to a block."

There is no mention of accessing internal _variables_ in this way. It
is true that _scoping_ works in the same way for both variables and
place-names, in that a label A: defined within a block has nothing to do
with a label A: defined outside the block, the only access being through
the dot notation, just as a variable x defined within a block has nothing
to do with a variable of the same name defined outside the block; but
there's nothing about accessing the values of internal variables.

The only reference to this sort of thing in the groff pic documentation
("man pic") is to the removal of the restriction that "dot-access" was
only one level deep (i.e. you could do A.B but not A.B.C):

  "There is no limit to the depth to which blocks can be examined.
   For example, ... circle at last [].A.B.C is acceptable."

I'm not seeing any other references to access to block internals anywhere.

Have you mis-interpreted "variable scoping works like object scoping"
or have you seen something I've missed?

In particular, if your statement "variable scoping works like object
scoping" is a literal quotation from somewhere, where did you see it?

The nearest I can find anywhere is the following quote from Eric Raymond's
"Making Pictures with GNU Pic" where (Section 10.2) it says:

  "Blocks are also a variable-scoping mechanism, like a groff(1)
   environment. All variable assignments done inside a block are
   undone at the end of it. To get at values within a block,
   write a [sic] name of the block followed by a dot, followed by the
   variable or label you want. For example, we could refer to the
   center of the box in the above composite as last [].Caption
   or A.Caption."

None of this contradicts what I've said above except for the words
"variable or". There is no other reference in Raymond's document
to accessing internal variables of a block; and indeed the statement
that a variable assignment is undone at the end of a block would
imply that it is inaccessible. The example he gives is of course
a label ("Caption").

NOTE that in your example above (P.Q.x) the "x" is not a variable;
".x" is a built-in name for the x-coordinate of a point, so that
"P.Q.x" is the x-xoordinate of the centre of the object named Q
within the object named P. It might be that this is the sort of
"variable" that Raymond meant in the above quotation.

Any clarification you can provide would be welcome!

With thanks,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 13-Feb-00                                       Time: 11:37:25
------------------------------ XFMail ------------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]