Better array support?

Started by itistoday, December 02, 2007, 06:44:18 PM

Previous topic - Next topic

itistoday

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.  :
Get your Objective newLISP groove on.

cormullion

#1
Sounds like a good idea - for all types to be equal!



You can always sort this way:


> (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))


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.

Jeff

#2
Arrays don't work the same as lists underneath.  I think that newLISP arrays are meant to be mathematical arrays, not like PHP arrays.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

itistoday

#3
Quote from: "cormullion"Sounds like a good idea - for all types to be equal!


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.
Get your Objective newLISP groove on.

cormullion

#4
nice one Lutz!


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))

itistoday

#5
Quote from: "cormullion"nice one Lutz!


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! :D
Get your Objective newLISP groove on.

Lutz

#6
QuoteAwesome! Thanks Lutz! :D


You are welcome. Always read the release/changes notes. Many of the user suggestions make it into a new version shortly, others are noted and may show up later.



Lutz