The new version of Felix puts a warning on assigning to a non-lvalue.
In theory, assignment doesn't exist in Felix. Instead we use the procedure
px <- v
where px is a pointer. We translate
p = v
to
(&p) <- v
We also translate
&(a.b)
to
(&a).b
Structure lookup handles this, the result is a pointer to the b component.
If b if a C binding marked "lvalue" then the translation to
&(f b)
also works (in general). However Felix functions cannot return lvalues (only C
bindings are allowed to do that).
This creates a problem:
WARNING: binding address of expression &((subscript (char_array_4, i))) gave
error:
Flx_exceptions.ClientError(_, "[bind_expression] [4]Address application of
non-lvalue function subscript in (subscript<8115>[char^4, char, int]
(index_18362<18362>, index_18359<18359>))\ndefined
here:\n/Users/johnskaller/felix/build/release/lib/std/array_class.flx: line 6,
cols 1 to 56\n5: \n6: fun subscript[I in ints] (x:t, i:I) => get
(x,i.size);\n ********************************************************\n7:
\n")
/Users/johnskaller/felix/build/release/lib/codec/base64.flx: line 139, cols 7
to 38
138: in_len--;
139: char_array_4.[i] = enc_str.[in_];i++; in_++;
********************************
140: if (i == 4) do
The problem here is that the subscript function is a *virtual* function.
In general, it will NOT return an lvalue, even if a particular instance does.
Therefore, array subscript expressions cannot be used on the LHS of an
assignment.
unless the lookup binds to array subscript directly (rather than through
virtual function).
Note it all works for a carray, because that isn't an array! It has no known
length!
It won't work for a native array, nor will it work for a varray or any other
array
kind which is bound by the typeclass ArrayObject.
Of course the set method works fine. So really the only solution is to change
x.[i] = fred
into
ArrayObject::set(x,i,fred)
The problem is that whilst
x.0 = 1;
works fine for a tuple, it doesn't for an array (which is a tuple!!!)
because the subscript operation is user defined.
Mmmm .. :)
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language