repeated var in output argument

View: New views
2 Messages — Rating Filter:   Alert me  

repeated var in output argument

by Dupuis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I recently tracked down a bug in a program I wrote due to a typo in the names of output variables, so one of them was repeated twice. Basically something as
[U, S, S]=svd(randn(3,3)) # correct: [U, S, V] = ...
but, due to the length of the line, I didn't notice until close inspection.
 
Now, a funny thing: octave is not bug-to-bug compatible with matlab with regard to this behaviour.
Octave 2.9.19 : print S a first time with values only on the main diagonal, and a second time as a unitary matrix.
Matlab 6.1 : print S the two times as a unitary matrix
Afterwards, in both case, S contains the unitary matrix, the diagonal matrix is lost.

Would it be possible to issue a warning if some variable is repeated in the output arguments of a function call ? This is a stupid typo, but as problematic as
if (x=1) # instead of (x==1)

In the first place, this is a problem in the way the function call is written. I would find interesting to add a feature to detect such overwriting of variables.

Best regards

Pascal Dupuis

repeated var in output argument

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11-Dec-2007, Dupuis wrote:

| I recently tracked down a bug in a program I wrote due to a typo in the
| names of output variables, so one of them was repeated twice. Basically
| something as
| [U, S, S]=svd(randn(3,3)) # correct: [U, S, V] = ...
| but, due to the length of the line, I didn't notice until close inspection.
|  
| Now, a funny thing: octave is not bug-to-bug compatible with matlab with
| regard to this behaviour.
| Octave 2.9.19 : print S a first time with values only on the main diagonal,
| and a second time as a unitary matrix.
| Matlab 6.1 : print S the two times as a unitary matrix
| Afterwards, in both case, S contains the unitary matrix, the diagonal matrix
| is lost.
|
| Would it be possible to issue a warning if some variable is repeated in the
| output arguments of a function call ?

If you also want a warning if the same expression is repeated, then I
don't see a simple way to do it.

Perhaps it would be better to rework the way the printing is done in
the tree_multi_assignment::rvalue (int) function in src/pt-assign.cc
so that instead of doing

  loop over all elements
    perform assignment
    print
  end loop

we do

  loop over all elements
    perform assignment
  end loop

  loop over all elements
    print
  end loop

but this change might not be trivial given the current
implementation.  I'd consider a patch, but not until after 3.0.

jwe