Skip to content

Redefining a hidden expression #129

@tueda

Description

@tueda

Some people use redefining expressions in their programs, although it is not a good idea (On allwarnings warns for them). For example,

On allwarnings;
L F = 1;
.sort
L F = F + 1;
.sort
On names;
P;
.end
FORM 4.1 (Oct 13 2016, v4.1-20131025-246-gb13522f) 64-bits  Run: Fri Oct 14 17:23:14 2016

test.frm Line 4 --> Warning: Expression is replaced by new definition

 Expressions
   F(local)
 Expressions to be printed
   F

   F =
      2;

The warning can be avoided by, for example, the following "Drop-and-Exchange" idiom:

On allwarnings;
L F = 1;
.sort
Drop F;
L tmp = F + 1;
#exchange F,tmp
.sort
On names;
P;
.end
FORM 4.1 (Oct 13 2016, v4.1-20131025-246-gb13522f) 64-bits  Run: Fri Oct 14 17:45:20 2016

 Expressions
   F(local)
 Expressions to be printed
   F

   F =
      2;

The above example is just a tip to write a strict (or ascetic) code, and actually redefining expressions is harmless.

Now, a horrible mess starts when one redefines a hidden expression. Case (1):

L F = 1;
.sort

#procedure redefine()
  Hide F;
  .sort
  L F = F + 1;
  .sort
#endprocedure

#do i=1,5
  #call redefine()
#enddo

On names;
P;
.end
FORM 4.1 (Oct 13 2016, v4.1-20131025-246-gb13522f) 64-bits  Run: Fri Oct 14 17:29:25 2016

 Expressions
   F(local-hidden) F(local) F(local) F(local) F(local) F(local)
 Expressions to be printed
   F F F F F

   F =
      2;

   F =
      2;

   F =
      2;

   F =
      2;

   F =
      2;

And case (2):

L F = 1;
.sort

#procedure redefine()
  Hide F;
  .sort
  L tmp = 1;
  .sort
  Drop tmp;
  L F = F + 1;
  .sort
#endprocedure

#do i=1,5
  #call redefine()
#enddo

On names;
Unhide;  * show all hidden expressions
P;
.end
FORM 4.1 (Oct 13 2016, v4.1-20131025-246-gb13522f) 64-bits  Run: Fri Oct 14 17:31:28 2016

 Expressions
   F(local-to be unhidden) F(local-to be unhidden) F(local-to be unhidden) 
   F(local-to be unhidden) F(local-to be unhidden) F(local)
 Expressions to be printed
   F F F F F F

   F =
      1;

   F =
      2;

   F =
      3;

   F =
      4;

   F =
      5;

   F =
      6;

So expressions are cloned with the same name, instead of replacing the existing expression. In the case (2), one may not notice the duplications of expressions (they are hidden) and can be a big pitfall leading to performance loss with hidden files in a large-scale calculation. It might be better to

  • forbid/warn such redefinitions, or
  • delete the existing hidden expression in such a case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions