On 19/06/2009, at 2:40 PM, Erick Tryzelaar wrote: > But there's no way to say "it's a type error to modify this array" > like C/C++ does. So, is this something we'd want? I personally think > something like this would be useful, and I'd bet it'd help with > optimization. We'd probably want something like this to work beyond > just arrays and pointers.
"const" is the wrong idea though. It may help, but it isn't the same as int immutable x = 1; int immutable *px = &x; With "const" a function promises not to modify the pointed at value. This helps the caller make optimisations. With "immutable" the caller AND the callee promise not to modify the value, this helps the callee make optimisations, in particular it allows cache = *px and the function knows cache == *px always. There is a language (forget the name, something C like) which specialises in pointer "kinds". However the original question is syntactic: even if Felix allows var x = 1; x += 1; by simply incrby : &int * int; there is no way to make a C primitive return an lvalue. This means we have to have, for example Carray::get (a,i) Carray::set(a,i,v) and then x.[i] += v can be written: set(a,i,get(x,i)+v) but that is a long way off the C notation. We could do a->[i] <- a.[i] however, where a->[i] // means &a[i] in C > > One way we could limit this a little bit is to make value arrays > immutable, where these would be type errors: > > # val x = 1,2,3; > # x.[0] = 5; <- type error > # proc foo[N] (x:array[int,N]) { x.[0] = 5; } <- type error > This is already an error, just not a type error. However this is OK: var x = 1,2,3; x.(0) = 99; as it should be, because x is a variable. -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language