L1VM - array

Here are two small programs to show how arrays can be used in Brackets. The second one uses “,” commas to separate the array elements and the first one uses spaces only:

// array-demo.l1com
// array with values demo
// shows how to set up an array
// and how to access the elements
//
#include <intr.l1h>
(main func)
    (set int64 1 zero 0)
    (set int64 1 one 1)
    (set const-int64 1 offset 8)
    (set int64 1 ind 0)
    (set int64 1 f 0)
    (set int64 1 num 0)
    (set int64 1 realind 0)
    // set array data using spaces as elements separator
    (set int64 10 array 10 5 8 4 3 2 7 23 45 30)
    (set int64 1 maxarray 10)
    // print array 
    (for-loop)
    (((ind maxarray <) f =) f for)
        ((ind offset *) realind =)
        (array [ realind ] num =)
        print_i (num)
        print_n
        ((ind one +) ind =)
    (next)
    exit (zero)
(funcend)
// array-demo-2.l1com
// array with values demo
// shows how to set up an array
// and how to access the elements
//
#include <intr.l1h>
(main func)
    (set int64 1 zero 0)
    (set int64 1 one 1)
    (set const-int64 1 offset 8)
    (set int64 1 ind 0)
    (set int64 1 f 0)
    (set int64 1 num 0)
    (set int64 1 realind 0)
    // set array data using comma as elements separator
    (set int64 10 array 10, 5, 8, 4, 3, 2, 7, 23, 45, 30)
    (set int64 1 maxarray 10)
    // print array 
    (for-loop)
    (((ind maxarray <) f =) f for)
        ((ind offset *) realind =)
        (array [ realind ] num =)
        print_i (num)
        print_n
        ((ind one +) ind =)
    (next)
    exit (zero)
(funcend)

You can choose what you use. Both ways are legal code! Here is the output:

$ l1vm prog/array-demo -q
10
5
8
4
3
2
7
23
45
30