[Top][All Lists]

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

Re: transformation question

From: Ben Pfaff
Subject: Re: transformation question
Date: Wed, 26 Apr 2006 11:44:10 -0700
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Jason Stover <address@hidden> writes:

> Here is the scenario:
> A transformation is being executed to write data to
> the active file. There are other transformations pending,
> each of which has a variable in the dictionary, but none
> of those other transformations have executed yet. So before
> I do this:
>               obs = case_data (c, i);  

You mean, you do this within the procedure that executes the
transformation?  By that time, all variables created up to that
point should be initialized.

There is a rule about this that has not been written down
anywhere yet.  It can be stated like this:

        If you create a variable, then you are responsible for
        making sure that its value in the case is initialized by
        the time any later transformation has a chance to

Usually this is done by creating a variable and adding a
transformation that initializes it at the same time.

> I want to make sure variable i has something in it.
> Should I look at variable i's 'init' (v->init)? Or something
> else?

Setting v->init to 1 is one way to ensure that a variable will be
initialized, but it does not have the semantics that you are
expecting.  If you set v->init to 1, then that variable will be
set to 0 (or blanks, for a string variable) in the case being
used for transformations before the first case is processed.
This is desirable if the variable is created by a transformation
that might never be executed, e.g. by a COMPUTE transformation
(because it can be nested within a DO IF or LOOP or whatever that
might skip the COMPUTE entirely).

In fact, I'm not sure that ->init should really exist anymore.
It's set to 1 by default, only a few places in the code ever set
it 0, and I think that those are just a misguide attempt at
"optimization".  I seem to recall adding that member many years
ago as an "optimization", but I think it's a micro-optimization
at best.  It's the ->reinit member that's interesting (it's what
implements the LEAVE command and should probably be renamed).

I am beginning lately to realize that these rules, which so far
have existed only in my own head, are not obvious and I should
write them down.  At some point, therefore, I will start working
on a developers' section for the documentation that gives some

Finally: I'm a little confused about the context you're talking
about.  How (or why) would you be examining a variable before the
transformations that initialize it have executed?  It sounds like
there's some important fact here that I'm missing.
"If a person keeps faithfully busy each hour of the working day, he
 can count on waking up some morning to find himself one of the
 competent ones of his generation."
--William James

reply via email to

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