Request: dolist to work on arrays as well as lists

Pondering the philosophy behind the language

Request: dolist to work on arrays as well as lists

Postby TedWalther » Fri Feb 27, 2015 12:35 pm

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?
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther
 
Posts: 603
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

Re: Request: dolist to work on arrays as well as lists

Postby rickyboy » Fri Feb 27, 2015 2:48 pm

. . . 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.
(λx. x x) (λx. x x)
rickyboy
 
Posts: 554
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: Request: dolist to work on arrays as well as lists

Postby Lutz » Fri Feb 27, 2015 3:31 pm

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:
Code: Select all
(dolist (e L)
   (println $idx ":" e))

versus:
Code: Select all
(dotimes (i (length L))
   (println i ":" (L i)))

It was simple to add with one line of code:
http://www.newlisp.org/downloads/develo ... nprogress/
Lutz
 
Posts: 5259
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: Request: dolist to work on arrays as well as lists

Postby rickyboy » Fri Feb 27, 2015 3:36 pm

Nice!
(λx. x x) (λx. x x)
rickyboy
 
Posts: 554
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: Request: dolist to work on arrays as well as lists

Postby TedWalther » Fri Feb 27, 2015 11:16 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.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther
 
Posts: 603
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC


Return to Whither newLISP?

Who is online

Users browsing this forum: No registered users and 1 guest

cron