help-octave
[Top][All Lists]
Advanced

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

Re: looping over file objects


From: Przemek Klosowski
Subject: Re: looping over file objects
Date: Fri, 14 Nov 2003 10:30:03 -0500 (EST)

   I've added a few more functions to the CVS version of src/ov-file.h so
   that file objects will act like scalar values in more places, so your
   original idea will work, but my changes may not provide complete
   compatibility.  So, this brings up a question about what Octave should
   really do for file ids.  I like the idea of having more information
   about a file stored in the object returned from fopen, but since it
   causes compatibility problems, perhaps fopen should just return a
   scalar value.  Comments?

fopen() already returns the second optional value (the error message),
so we could just extend that:

 - return additional, structure value for three return arguments:

    fopen('abc')  => ans=3
    [a,msg,b]=fopen('abc') => a=3, msg='', 
b={id=3,name=abc,mode=r,arch=native,status=open}

 - return individual items: [fd,msg,nam,mod,arch,stat]=fopen('abc'); 

 - detecting what is the return argument type (not only their number),
   and returning a structure if it is a structure, and a scalar
   otherwise (I am not sure whether the interpreter does this
   currently---if not, this may require larger changes)

I always liked Perl's convention of 'context': various Perl functions
and objects return different values depending on whether they are used
in array or scalar context. The third option would be along those
lines: but it may require deepest changes in octave, both internal and
user-visible: I think the present philosophy is that the return type
is dictated and overriden by the callee function (although the
functions do modify their behavior by looking at the number of return
arguments).

In this new scheme, for instance,

   a.x=''; # 'a' is a structure
   a=svd(m)
      a= { u=... , s=..., v=...}

All in all, I think it might introduce too many incompatibilities,
unless someone can think it through and come up with a way to make
it backwards compatible.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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