bugGNU Octave - Bugs: bug #53331, Can't make function output...

 
 

bug #53331: Can't make function output argument persistent (poor man's constant)

Submitter:  Oliver Heimlich <oheim>
Submitted:  Mon 12 Mar 2018 08:52:25 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  siko1056
Originator Name:  Oliver Heimlich Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 22 Mar 2018 07:40:17 PM UTC, comment #10: 

Thank you, works for me.

Oliver

Anonymous
Thu 22 Mar 2018 07:36:24 PM UTC, comment #9: 

Thanks Mike.  I close this one.

Kai Torben Ohlhus <siko1056>
Group Member
Thu 22 Mar 2018 06:19:10 PM UTC, comment #8: 

Doc addition looks good to me, can we call this fixed?

Mike Miller <mtmiller>
Group Member
Wed 21 Mar 2018 09:49:19 PM UTC, comment #7: 
Kai Torben Ohlhus <siko1056>
Group Member
Wed 21 Mar 2018 09:27:18 PM UTC, comment #6: 

Confirm comment #4.  Matlab R2017b errors hard on functions like these: "The current use of 'x' is inconsistent with its previous use or definition (line 1)."


function x = foo ()
  persistent x;
  x = 1;
end


Thus close this item as "won't fix"?

Kai Torben Ohlhus <siko1056>
Group Member
Sun 18 Mar 2018 10:05:23 AM UTC, comment #5: 
Oliver Heimlich <oheim>
Tue 13 Mar 2018 04:59:14 PM UTC, comment #4: 

I don't fully understand the underlying reasons either, but I guess that it may be described by jwe's comment

> I would prefer that we disallow making existing variables (including function parameters) global the same as we do for persistent


IOW, when the function definition is parsed, the output parameters are already "defined" in some sense as local variables? So then having a "persistent" statement overriding the output argument declaration is conflicting somehow.

And here is a quote from the Matlab official docs

> MATLAB also errors if you declare any of a function's input or output arguments as persistent within that same function


I think it would be helpful if this were mentioned in our docs, along with an example showing the correct way to do it.

Mike Miller <mtmiller>
Group Member
Tue 13 Mar 2018 08:42:48 AM UTC, comment #3: 

Yes, the discussion in bug #52699 suggests that this change is intended.  Yet, I still don't understand the reason for the change.

Oliver Heimlich <oheim>
Tue 13 Mar 2018 08:20:37 AM UTC, comment #2: 

AFAIU, this change was intended. See e.g. the discussion in bug #52699.

Pantxo Diribarne <pantxo>
Group Member
Mon 12 Mar 2018 09:00:00 PM UTC, comment #1: 

Confirmed, and it is a regression from 4.2.

Can be worked around with a simple no-cost copy of the constant to the return value:


function x = foo ()
  persistent y = 1;
  x = y;
endfunction


Mike Miller <mtmiller>
Group Member
Mon 12 Mar 2018 08:52:25 PM UTC, original submission:  

The following is a common(?) idiom in Octave to define a constant value: To define a function without parameters.

To prevent multiple initialization of a computed value, it can be made persistent.  However, that fails in the current dev version.


>> function x = foo (); persistent x = 1; endfunction
>> foo
error: can't make function parameter x persistent
error: called from
    foo at line 1 column 22


I can understand that input(!) arguments cannot be made persistent.  But, shouldn't that be possible for output arguments?

Oliver Heimlich <oheim>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by oheim (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-22 siko1056 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2018-03-22 siko1056 Assigned toNone siko1056
    2018-03-21 siko1056 StatusConfirmed Need Info
    2018-03-12 mtmiller StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code