Better array support?
Better array support?
Is this planned for the future? It would be nice if more of the functions that operated on lists would also operate on arrays, for example (sort). As a big fan of newLISP I would be glad to help implement this myself, it's just that school won't give me a minute's rest. :\
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Sounds like a good idea - for all types to be equal!
You can always sort this way:
But that will probably be slightly slower than an array-optimized sort, and presumably you're using arrays longer than 200 elements or so for speed reasons anyway.
You can always sort this way:
Code: Select all
> (set 'arry (array 3 3 (randomize (sequence 1 100))))
((83 61 84) (33 68 42) (30 63 46))
> (sort (array-list arry) (fn (x y) (< (x 2) (y 2))))
((33 68 42) (30 63 46) (83 61 84))
You can sort a list that contains mixed-type elements, so I see no reason why you couldn't do the same for an array. I wrote a C vector implementation a while ago that let you do this, you can use it just like a list, except insertions/removal from anywhere other than the back take longer. You just have an array of pointers to "DataHolder" unions that can be anything. It would then follow the same rules that sort uses for lists.cormullion wrote:Sounds like a good idea - for all types to be equal!
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
nice one Lutz!
Code: Select all
newLISP v.9.2.9 on OSX UTF-8, execute 'newlisp -h' for more info.
> (set 'a (array 2 2 (randomize (sequence 1 10))))
((8 7) (2 10))
> (sort a)
((2 10) (8 7))
Awesome! Thanks Lutz! :Dcormullion wrote:nice one Lutz!
Code: Select all
newLISP v.9.2.9 on OSX UTF-8, execute 'newlisp -h' for more info. > (set 'a (array 2 2 (randomize (sequence 1 10)))) ((8 7) (2 10)) > (sort a) ((2 10) (8 7))