newLISP Fan Club

Forum => newLISP newS => Topic started by: itistoday on December 02, 2007, 06:44:18 PM

Title: Better array support?
Post by: itistoday on December 02, 2007, 06:44:18 PM
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.  :
Title:
Post by: cormullion on December 03, 2007, 01:08:09 AM
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.
Title:
Post by: Jeff on December 03, 2007, 04:56:39 AM
Arrays don't work the same as lists underneath.  I think that newLISP arrays are meant to be mathematical arrays, not like PHP arrays.
Title:
Post by: itistoday on December 03, 2007, 03:13:35 PM
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.
Title:
Post by: cormullion on December 13, 2007, 04:24:03 AM
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))
Title:
Post by: itistoday on December 13, 2007, 06:57:21 AM
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
Title:
Post by: Lutz on December 13, 2007, 07:25:22 AM
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