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 23:26:22 -0000 (GMT)

On 13-Feb-00 karan bhatia wrote:
> 
> 
>>"But according to the documentation, variable scoping works like object
>>scoping" -- according to what documentation?
> 
> I'm interpreting the documentation that you yourself quote:
> 
>>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."
> 
> Doesn't this (and the example of last [].Caption) imply that i can get 
> do the same for variables defined within the last []?  "followed
> by the _variable_ or label you want".  

OK. Now that we agree about what is being referred to, in my opinion
it was an error for Eric Raymond to include the words "variable or".
Pic did not originally allow reference to in-block variables (as
opposed to objects); there is nothing in groff's own documentation which
suggests that it should; and GNU pic in practice does not allow it!

>>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").
> 
> I think we agree that the above reference implies that i can do 
> something like last [].variable.  This is exactly the documentation
> i was refering to.  So either the documentation should clarify
> this important distinction between variables and labels (and take
> out "variable or") or perhaps there is a way to add that functionality?

While Eric Raymond's paper is a good user's manual for GNU pic, it is not
part of the "official" GNU documentation for groff. However, your point is
noted for the future documentation which is currently being prepared.

> So perhaps this is not a bug, perhaps i can make this into a 
> feature request.  Is this a difficult feature to add?

I think it would not be easy in the form you expect, because it would
involve re-structuring the pic code. Nor do I think it would be desirable.
A variable which is assigned a value inside a block is local to the block
and ceases to exist on exit from the block (in this it is like
variables defined within {...} in C). On the other hand, a variable
defined outside a block is visible within the block (i.e. is global
with respect to the block) -- again, like C. So, in principle,
if you need to see a variable both inside an outside a block,
assign its value outside the block. I'm aware, of course, that
it might be more _convenient_ to define the value within the block.
A variable which already exists outside a block, and is assigned a new
value inside the block, reverts to its original value on exit from
the block. This is useful because it allows "re-use" of block
code without having to rename variables (also existing outside the
block) which you do not want to interfere with.

There might be merit in introducing a new keyword (e.g. "global")
to make a variable whose value is assigned within a block the
same variable as one existing outside the block, so that a re-assignment
within the block is preserved on exit. This might not be too difficult to
implement.

>>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.
> 
> This is another important point that should be clarified in raymond's
> documentation.

It is already in Raymond's document (Section 12: Expressions) and
in the original Kernighan manual "PIC -- A Graphics Language ... "
(AT&T Comp. Sci. Tech Rept. No. 116), Section 6 (Variables, Expressions,
and Builtin Functions). It is not at present in the GNU "man pic" which
still (though this will ultimately change) "describes only the
differences between GNU pic and the original version of pic."

I hope this helps; any comments, by anyone, would be welcome.

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 13-Feb-00                                       Time: 23:26:21
------------------------------ XFMail ------------------------------


reply via email to

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