Farray is a mess.  Here's the problem:

I'm considering both an array and a pointer to it as equivalent
array values. Also pointer to an array is considered as an array object.

The idea was: you cannot modify an array value. But if your array
is in a variable you can take the address to get an array pointer.
Then like C you can still get the values by indexing, but you can
also store.

This works with get/set methods but not with index notation:

        (&a) . i <- 1


because it is inconsistent. I tried this for an array or arrays:

        var x : array[array[double,100],100]; 
        (&x) . i . j <- 1

and it fails because (&x) . i is a an array of double value.

Structure address calculations propagate correctly:

struct X { x:int; };
struct Y { y:X; };

var a = Y ( X ( 1) );
println$ a . y . x;
(&a) . y . x <- 22;
println$ a . y . x;

The reason is that &a is a pointer and so &a . y is a pointer
and so &a . y . x is a pointer.

But for an array:

        (&a) . i

is a value, not a pointer.

Now, after modifying the library code I got this to work:

var x : array[array[double,100],100];
for var i in 0 upto 99 do
  for var j in 0 upto 99 do
    var p1 : +array[double,100] = (&x).stl_begin + i;
    var p2 : +double = p1.stl_begin + j;
    p2 <- #rand.double / RAND_MAX . double;
  done
done

In other words you can write:

        ((&x) . stl_begin + i) . stl_begin + j <- 1

but that\s the only way to do it (short of using compact linear types).

To make address calculations propagate,

        (&x) . i

has to be a pointer, not a value. But this means &a would become
an array of pointers. It would not be writable as such so it would
be an actual array value: to get the pointed at value you'd
have to dereference.

Note this problem didn't manifest with ordinary arrays
because

        p <- v

decays to

        (*p) = v

i.e. even though Felix claims <- is fundamental and = is sugar
the implementation is the other way around :)

This will break some things! But it is right I think.
Actually .. it's pretty cute!!

So the change is: array[t,n] is an ArrayValue and

        &array[t,n] is an ArrayValue[&t,n]

It follows:

        var x = 1,2,3;
        &x . 1 <- 99;

will work. note the returned value is &int so it is NOT incrementable!


--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to