Re: [Vala] A few questions



Abderrahim Kitouni wrote:

[indent=2]
const MAXVALUE: int = 50
init
 myarray : array of int = {1..MAXVALUE}

Isn't there a similar way to declare an array using only minimum and maximum
values?

No, arrays indices always start from 0, so you just pass the length, e.g.
myarray : array of int = new array of int [50]
(I hope you don't mean the array should contain elements from 1 to 50)

As a matter of fact, initially I was going to use values from 13
trought 19 to better illustrate my concern, but ultimately decided not
to, to avoid people from asking why would I need to do such a thing.
However, if according to the official documentation it is valid to
declare a non-zero starting array like this:

const int_array : array of int = {1, 2, 3}

Then it _should_ be equally possible to declare an array using a
range, because in this example only 3 values were needed, but what if
several values are needed and the array must start from an arbitrary
number other than zero?
Since this functionality is not currently present in Genie (and
presumably Vala), I think implementing it could be quite useful to
prevent unnecessarily complex workarounds.
Once implemented, it could obviously be used in all kinds of useful
stuff, like cases or simple comparisons.

Jürg, Pleeeeaaaase??? (pretend I am using the style of Roger Rabbit)

Also, while looking for genie-related stuff, it seems you can use the
backslash to split lines (at least that's what I see in
valageniescanner.vala, starting from line 485), however I have tried using
it (with different indentations) without success. Could anyone post a
snippet of how to use it, for example to pass parameters to a function, each
in a separate line?

[indent=2]
init
  string.join (",",    \
              "item1", \
              "item2")

the backslash must be the last character on the line

That's odd, I tried to compile a similar example from Windows and the
compiler raised a syntax error, I was using Vala 0.78
Perhaps it's a line termination issue, I cannot check right now
because I am at work. Can anyone else check if this is a error of the
Windows build?

Regards, Hugo



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