Better array support?

Notices and updates
Locked
itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Better array support?

Post by 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. :\

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

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))
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
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

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

Artful code

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

cormullion wrote: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.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

cormullion 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))
Awesome! Thanks Lutz! :D

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Awesome! 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

Locked