bugGNU Octave - Bugs: bug #34145, need for ifdef test

 
 

bug #34145: need for ifdef test

Submitted by:  None
Submitted on:  Sat 27 Aug 2011 12:03:01 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 1 - LaterItem Group: Feature Request
Status: InvalidAssigned to: None
Originator Name: Originator Email: -unavailable-
Open/Closed: ClosedRelease: 3.4.0
Operating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Sat 27 Aug 2011 06:45:10 PM UTC, comment #3:

> Symantics and word games are irrelevant.


I'm not sure what to write, then. You want isnan, which is a function that checks if each element of a matrix is NaN or not to crossreference exist, because you were thinking of the phrase "is defined?" instead of "exists?" The exist function is documented in the section of the manual that about gathering information of the environment, related to the who and whos functions, which already cross reference exist. I'm all for better documentation, but I don't exactly understand the relationship between a function that tests each element of a matrix to a function that tests if the workspace has a variable, except, as you put it, semantics and word games.

That being said, I did make the following change on the stable branch:

http://hg.savannah.gnu.org/hgweb/octave/rev/aaf6fbb2512f

Will that suffice, instead of putting cross references to "exist" in all of those functions?

Jordi GutiƩrrez Hermoso <jordigh>
Project Administrator
Sat 27 Aug 2011 06:03:01 PM UTC, comment #2:

Thanks that was what I was looking for.

Could I suggest this is in the "see also" list for isnan et al. That would help discover it.

See also: note isnan: doc-isnan, note isinf: doc-isinf, *note
isfinite: doc-isfinite.

Just wildly guessing at what such a function is called is not guaranteed to give success and having done a tour of the doc on these test functions I saw no mention of exist() .

Clearly if it was defined it would exist. If it does not exist it is equally not defined. Symantics and word games are irrelevant.

Better cross-referenceing in the doc would be useful here. A simple oversight, I'm sure.

Thanks for pointing me at the relevant funciton.

Anonymous
Sat 27 Aug 2011 02:07:50 PM UTC, comment #1:

You aren't supposed to be able to create an undefined variable in Octave. All variables have values. So asking whether a value is defined isn't the right question. Maybe you want to ask whether a variable already exists? Try "help exist".

John W. Eaton <jwe>
Project Administrator
Sat 27 Aug 2011 12:03:01 AM UTC, original submission:

It seems there is not direct way to test whether a variable has been defined or not.

Since both NA and NaN are actually assigned values it does not seem there is a basic test for unassigned variables.

A work around is a try... catch structure around an attempt to reference the variable but it's a bit messy .

isdef(varname) could be cleaner unless I'm missing a trick.

try
i=i;
catch
i=1;
end_catch_try

if ! isdef(i) i=1;

OR

isdef(i,1); # to provide a default value.

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jordigh (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 27 Aug 2011 02:07:50 PM UTCjwePriority5 - Normal=>1 - Later
      StatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1