From: Brian H. <bri...@ql...> - 2003-04-22 03:01:37
|
On Tue, 22 Apr 2003, Nicolas Cannasse wrote: > > According to the NIST, what I've implemented is a dynamic array: > > http://www.nist.gov/dads/HTML/dynamicarray.html > > > > I hereby propose we rename it dynarray then. I'm not worried about losing > > revision control history- if I hadn't checked it in, we wouldn't have had > > any to lose :-). > > It would be perhaps nice to have then then same name-prefix for both > "mutable" list and "mutable" array. > RefList / RefArray ( this one make sense since the type Xarray.t contains a > mutable 'array field ) > or > DynList / DynArray > No insult, but reflist confuses me. With a few exceptions, it looks like it's just a ref to a list, and the functions just dereference the ref and call the appropriate list function. I suppose I'm saying that I'm seeing enough meat on the bone here to make it a worthwhile library. In any case, I don't think both it and xarray (whatever it gets renamed to) should have the same prefix. Arrays in ocaml are already mutable- that's implicit. But their size is immutable once created. So we're adding the feature of being able to resize the array. Likewise, in reflist, we're adding the feature of being able to mutably change the head of a list. For dynlist I'd say it should be fully dynamic, like dynarray is. Append and prepend and insert into the middle. I need to play with how this should work a little. Hmm. Playing around a little bit, I notice that: # let x = [| 1; 2; 3 |];; val x : int array = [|1; 2; 3|] # x. (1);; - : int = 2 # x . (3);; Exception: Invalid_argument "Array.get". # x.3;; Syntax error # x. 3;; Syntax error # let ( %. ) = Array.get ;; val ( %. ) : 'a array -> int -> 'a = <fun> # x%.(3);; Exception: Invalid_argument "Array.get". # x%.(2);; - : int = 3 # (3);; - : int = 3 # x %. 2;; - : int = 3 # Of course, %. looks like a floating point operator. But this does open some possibilities for an accessor operator mostly like .(). Brian |