[Nickle] Reference semantics are confusing in Nickle

Bart Massey nickle at po8.org
Sat Nov 27 16:23:13 PST 2004


Confusing doesn't begin to describe it.

The deal is this: references are *initialized* to point to
storage, and then when they are *assigned to* the storage is
stored into.  IOW, the semantic of a reference *initializer*
is that it is treated as bare, while the semantic of a
reference *expression* is that it is syntactic sugar for the
corresponding pointer expression with a star on the front.

An example:

  $ nickle
  > &int x = reference(5);
  > &int x = &5;  /* this works, BTW, and does the right
                     thing with static typechecking */
  > x = &7;  /* static type error: equiv to *(x) = &5; */
  <stdin>:3: Incompatible types, left 'int', right '*int', for = operation
  > &x = &7;  /* ok, this makes x a reference to new storage */
  > x = 9;  /* this changes the value in x's current storage */
  
The hash just makes things more confusing: the same
semantics apply :-).

We're willing to listen to suggestions: we agree that it's
hard to understand.  However, we haven't cooked up any
scheme we like better yet.

HTH,

	Bart

In message <1101596708.6433.209567740 at webmail.messagingengine.com> you wrote:
> 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
> 
> 
> _______________________________________________
> Nickle mailing list
> Nickle at nickle.org
> http://nickle.org/mailman/listinfo/nickle



More information about the Nickle mailing list