Hey, skaller wrote: > On Tue, 2006-09-26 at 21:47 +1000, Jonathan Kelly wrote: > >> Hi, >> >> am I right in deducing there are no arrays in felix, despite the >> temptingly titled sections in the tute and ref man? I mean the sort of >> arrays a C/C++ programmer would be thinking of, obviously. >> > > Felix has first class fixed length arrays whose length > is determined by a compile time constant, exactly > the kind in this C: > > #define n 1000 > struct X { int array[n]; } > > It also has C style arrays: > > module Carray > { > requires cstdlib; > open C_hack; > > fun array_alloc[t]: int -> ptr[t] = > '(?1*)std::malloc(sizeof(?1)*$1)'; > .... > > thanks, that was the opening I needed. I implemented a test using Carray using the subscript function to access, then thought, I wonder if there's sugar for that and tried "x.(i)", (which is what I had tried for the felix array, seeing as the doco said the arrays were really tuples), but that didn't work, so I tried x[i], nope, then x.[i]. Ta Dah.
Here's what I used to demonstrate the arrays stuff, if you'd like it for the tute ... hack at will. //------------ #import <flx.flxh> open Carray; // needed for array_alloc() and subscript() open Long; // needed for multiplying longs val n = 8; var x = array_alloc[int](7); var y = array_alloc[long](n); var z : int ^ 7; // first class felix array proc s (i:int) { if i < 7 do print i; endl; subscript[int](x, i) = i * 2; y.[i] = C_hack::cast[long,int](i) * 3L; z.[i] = i * 4; s(i + 1); done; } s(0); print "dah\n"; print (subscript[int](x, 4)); endl; print (y.[4]); endl; print (z.[4]); endl; //------------ > which are unsafe and can't contain Felix heap pointers. > You can also use STL vector of course, but again > only for C++ data types or pointer-free Felix ones. > > We're working on a fixed length array whose length > is determined at construction time dynamically, > called 'varray' in module Varray. > > And possibly also a dynamically extensible array > like STL vector. > > The difficulty here is that there are LOTS of different > options. Some are hard, for example an extensible > array which moves its storage around: the way STL handles > this is very inefficient. Using mmap/realloc is much faster, > but C++ does not provide a move or 'relocate' method > for objects: realloc doesn't work with copy ctor. > > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language