[Nickle] Reference semantics are confusing in Nickle

James LaMar giantrobot at f-m.fm
Sat Nov 27 15:05:08 PST 2004


I don't understand this behavior:

> &int i = 5
->     &int i = 5;
<stdin>:1: Incompatible types, storage '&int', value 'int', for
initializer
> &int i = reference(5)
&5

Ok, this makes sense.

> (&int)[int] j 
(&int [int]) {}
> j[5] = reference(5)
->     j[5] = reference (5);
<stdin>:4: Incompatible types, left 'int', right '&poly', for =
operation

Why is this ill-typed?

> j[5] = 5
Unhandled exception uninitialized_value ("uninitialized hash element")
<stdin>:5:     j[5] = 5;

Why doesn't this work?

Same confusion with [...] arrays:

> (&int)[...] k = {}
(&int [...]) {}
> k[0] = reference(5)
->     k[0] = reference (5);
<stdin>:9: Incompatible types, left 'int', right '&poly', for =
operation
> k[0] = 0
Unhandled exception invalid_array_bounds ("Array index out of bounds",
(&int [...]) {}, 0)
<stdin>:10:     k[0] = 0;
> 

Yet this works -- after a fashion:

> (&int)[10] l = {[i] = reference(i)}        
(&int [10]) {&0, &1, &2, &3, &4, &5, &6, &7, &8, &9}
> l[0] = 0
0
> l
(&int [10]) {&0, &1, &2, &3, &4, &5, &6, &7, &8, &9}
> l[0] = 1
1
> l
(&int [10]) {&1, &1, &2, &3, &4, &5, &6, &7, &8, &9}
> 

Can someone please straighten me out?
-- 
  James
  giantrobot at f-m.fm




More information about the Nickle mailing list