(module main)

(fn empty_values () -> (vec i32)
  (std.vec.i32.empty))

(fn pair ((base i32)) -> (vec i32)
  (let values (vec i32) (std.vec.i32.empty))
  (let first (vec i32) (std.vec.i32.append values base))
  (std.vec.i32.append first (+ base 1)))

(fn echo ((values (vec i32))) -> (vec i32)
  values)

(fn length ((values (vec i32))) -> i32
  (std.vec.i32.len values))

(fn at ((values (vec i32)) (i i32)) -> i32
  (std.vec.i32.index values i))

(fn call_return_len () -> i32
  (std.vec.i32.len (echo (pair 20))))

(fn original_len_after_append () -> i32
  (let values (vec i32) (std.vec.i32.empty))
  (let appended (vec i32) (std.vec.i32.append values 1))
  (std.vec.i32.len values))

(test "vec i32 empty length"
  (= (std.vec.i32.len (empty_values)) 0))

(test "vec i32 append length"
  (= (length (pair 40)) 2))

(test "vec i32 index"
  (= (at (pair 40) 1) 41))

(test "vec i32 append is immutable"
  (= (original_len_after_append) 0))

(test "vec i32 equality"
  (= (pair 5) (std.vec.i32.append (std.vec.i32.append (std.vec.i32.empty) 5) 6)))

(fn main () -> i32
  (std.io.print_i32 (call_return_len))
  (at (pair 40) 1))
