user7450201
user7450201

Reputation: 11

Create a Genie Array

Hi I have a Problem with Arrays.

I have class Arr the var a = new array of int[100] is the problem.

The example works but wenn I put the var a ... behind class Arr (return) (Tab) i have this error message :

arr.gs:3.2-3.4: error: syntax error, expected declaration but got `var' with previous `tab indent'

What's the problem. Sorry for my english , sorry I don't understand the editor

thanks

class Arr
    def arr_test()
        var a = new array of int [100]
        i : int = 0
        for i = 0 to 99
            a[i] = i
        for i = 0 to 99
            print "%4d",a[i]
init
    Intl.setlocale()
    var v = new Arr()
    v.arr_test()

Upvotes: 0

Views: 166

Answers (2)

txasatonga
txasatonga

Reputation: 419

I have tried your code in my computer and no problem, but the format of the indent was wrong.

Genie code indentation can be writed with tabs or spaces; If you uses spaces you must to explicit how many... like this [indent=4] at the start of the code. Like here http://manualgenie.blogspot.com.es/

But if you want to use tabs instead spaces (is more confortable) you must to ensure there is not spaces before any code line. Like here: http://genie.webierta.skn1.com/wiki/colecciones

For Vala/genie programming I use Geany editor and it has an option for replace all spaces in tabs, or all tabs in spaces in "Document" option of the task bar.

When the problem is how to use o where use "var" I will explain here: Var is used for declare and define one identifier(variable) in only one code line and for be used temporaly. But if you want to have global scope into the class, getting it useful for all the "def" procedures of the class, you must declare at the start of the class. Like the example above. Also, if we use "init" for declare it the class must be defined as "GLib.Object"

class Arr:GLib.Object
    a : array of int [] //declare
    init 
        a = new array of int [100] //define
    def arr_test()

        i : int = 0
        for i = 0 to 99
            a[i] = i
        for i = 0 to 99
            print "%4d",a[i]
init
    var v = new Arr()
    v.arr_test()

Aslo, you can declare it but define after in your "def" procedures. Like in this example:

class Arr
    a : array of int []
    def arr_test()
        a = new array of int [100]
        i : int = 0
        for i = 0 to 99
            a[i] = i
        for i = 0 to 99
            print "%4d",a[i]

    def arr_test2()
        a = new array of int [120]
        i : int = 0
        for i = 0 to 119
            a[i] = i
        for i = 0 to 119
            print "%4d",a[i]
init
    var v = new Arr()
    v.arr_test()
    v.arr_test2()

Note: In this case we don't use "init", therefore is not needed the declaration :GLib.Object.

Upvotes: 1

user7450201
user7450201

Reputation: 11

Thanks,

my Problem is not the tab or space. I have checked this.

This is the Problem :

class Arr

    var a = new array of int [100]

    def ...

init

...

... and so on.

It is one Tab no space.

Thanks

Upvotes: 0

Related Questions