Re: [Vala] readline from a FileStream?



Dov Grobgeld wrote:
Building on Frederik's answer, I built myself an iteratable interface to line reading which looks just like python. This is already pretty. :-)

I don't understand how the following works though:

            next_line = fi.dis.read_line (null, null) + "\n";
            return next_line!=null;

I would rather write it:

            next_line = fi.dis.read_line(null,null);
            if (next_line != null)
                next_line = next_line + "\n"

but that gives me an error of:

iter.vala:20.29-20.44: error: Arithmetic operation not supported for types `string' and `string'
                next_line = next_line + "\n";

why? What's the difference?

Regads,
Dov

Hi Dov,

it seems to have something to do with generics. I think inside the class
the name "string" is known as a new generic type, not as the original
"string" type, just as if you had written "class Iterator<Y>" instead of
"class Iterator<string>". With a generic type like Y the + operator is
not allowed, because Y could be of any type. I think instead of

private class Iterator<string> : GLib.Object, Gee.Iterator<string> { ... }

it should be

  private class Iterator : GLib.Object, Gee.Iterator<string> { ... }

then your string concatenation works fine, and now I would expect the
generic parts of the interface to be fixated on the type "string"
without introducing a new generic type, but unfortunately now the
compiler complains about an incompatible return type for get(). To me
this seems like a Vala bug.


Regards,

Frederik



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