help-octave
[Top][All Lists]
Advanced

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

Re: looping over file objects


From: pkienzle
Subject: Re: looping over file objects
Date: Sat, 15 Nov 2003 01:59:44 -0000

On 13 Nov 2003 at 21:51, John W. Eaton wrote:
> As workarounds, here are two ways, both of which should be compatible
> with Matlab.
> 
> First, adding 0 to a file object will convert it to a number, so you
> can write
> 
>   files = [stdout+0, file+0]
> 
> or, you could store them in a cell array instead:
> 
>   files = {stdout, file}
>   for i = 1:length (files)
>     fprintf (files{i}, ...);
>   end
> 
> 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?

Having just claimed on another list that file being a structure
rather than an integer hasn't caused any problems, I'm 
feeling a bit foolish.  So how about I dig myself in deeper.

Why don't you just define [file, file] to return an array of files?
Similarly, [struct,struct] could return an array of structs.

Right now with structs you can say:
    x.a = 1; x.b = 2; y.a = 3; y.b=4;
    f(1) = x; f(2) = y;
and access the individual structs with:
    f(1), f(2)
but you can't say:
    f = [x,y];

This would mean we would finally have to address the
horizontal,vertical concatenation issue that we've been
avoiding so long, but it is something we will need to do
eventually.

The thing is that I want graphics handles to behave in a similar
way: You should be able to store them in the same data structures
that you store scalars, but you should be able to update them
in place by assigning to their fields --- no need to go through
set(h,'name',value) when you want to say h.name=value.

Paul Kienzle
address@hidden



-------------------------------------------------------------
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]