On 17/02/2013, at 4:49 AM, john skaller wrote:

> 
> The problem is that a carray[T] = +T is an abstraction.
> It has get and set methods:
> 
>       get (a, i)
>       set (a,i,v)

So .. I'm a bit lost what to do here. Felix, lacking lvalues as such,
is going to have trouble with hacks the pretend they exist.

We can trick

        a = b

into

        &a <- b

as syntactic sugar for a whole variable but once you have arrays
with two kinds: real arrays and mere abstractions, there are issues.
Even if we can make

        a . i = 1;

work for a real array, that doesn't extend to library based abstractions.
Those abstractions can provide a deref operator returning a value,
and indexing returning a value:

        *a  
        a . i

by overloading but you cannot overload assignment, and more to the
point other mutators like:

        x ++

which also require an "lvalue" can be overloaded by

        incr (&x)

but that won't work if x is an abstraction, because you cannot overload
operator & either.

We might do:

        set a i v;

instead of the current

        set(a,i,v)

but this won't support other mutators like ++. The general operation
I use at the moment is actually

        a.stl_begin

which returns a +T. A more restricted form like:

        a . get_address

only works on the head of the array. Generally

        get_address (a, i)

allows all operations on the value slot:

        * ( get_address (a,i)) // returns value
        get_address (a,i) <- v // sets value
        incr (get_address (a,i)) // increment stored value

So actually the general form would be better served by

        a . i <- *(a . i) + 1

meaning that "a" should be considered a pointer, so you have to actually
deref it to get the value out. This is more or less how C handles arrays.

In Felix we might be able to do this:

        object a = 1;

and now 'a' is a variable, but the meaning of "a" is a pointer.
So the value is now *a, but you can do 

        a <- 2;

i.e. its an ordinary variable but the type is not T, but &T.
This is similar to the existing "ref" binder but backwards.
In effect, we would change the meaning of "var" so

        var x  ..

        x <- *x + 1

is correct. Hmm .. still lost.

I might just get rid of assignments except to whole variables.
See what breaks .. :)

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




------------------------------------------------------------------------------
The Go Parallel Website, sponsored by Intel - in partnership with Geeknet, 
is your hub for all things parallel software development, from weekly thought 
leadership blogs to news, videos, case studies, tutorials, tech docs, 
whitepapers, evaluation guides, and opinion stories. Check out the most 
recent posts - join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to