newLISP Fan Club

Forum => Whither newLISP? => Topic started by: TedWalther on February 27, 2015, 04:35:19 AM

Title: Request: dolist to work on arrays as well as lists
Post by: TedWalther on February 27, 2015, 04:35:19 AM
Lutz, could you enable array support in dolist?  I'm using 2.6.0; if this has been changed in later versions, disregard.



Edit:



And yes, I see the array-list function.  Is there a technical reason why it is better to explicitly do an array conversion, rather than iterating over the array directly?
Title: Re: Request: dolist to work on arrays as well as lists
Post by: rickyboy on February 27, 2015, 06:48:53 AM
Quote. . . rather than iterating over the array directly?

You can use `for` to iterate over an array directly.  But I assume you know that already.  Sorry.  I don't know what you are trying to do, but I am curious.  Good to see you, Ted.
Title: Re: Request: dolist to work on arrays as well as lists
Post by: Lutz on February 27, 2015, 07:31:28 AM
One could see an advantage of making dolist work on arrays in some cases, that you wouldn't have to specify the max N for a dotimes, while or for loop and expressions somehow are simpler because no indexing takes place:

(dolist (e L)
(println $idx ":" e))

versus:

(dotimes (i (length L))
(println i ":" (L i)))

It was simple to add with one line of code:

http://www.newlisp.org/downloads/development/inprogress/
Title: Re: Request: dolist to work on arrays as well as lists
Post by: rickyboy on February 27, 2015, 07:36:00 AM
Nice!
Title: Re: Request: dolist to work on arrays as well as lists
Post by: TedWalther on February 27, 2015, 03:16:30 PM
Thank you Lutz!



Rickyboy: principle of least surprise.  I use an array for speed and efficiency, but I use them the way I use lists.  In general, my brain gets tripped up if I can't use list functions on arrays, unless there is a specific reason why that list function is specific to lists but not to arrays.  I saw the recent changes Lutz made to support arrays as first class lists and they really made the language conceptually nicer, requires less brain state from me.