Post Reply 
Programming puzzles: processing lists!
04-25-2017, 03:01 AM
Post: #34
RE: Programming puzzles: processing lists!
(04-25-2017 01:11 AM)Claudio L. Wrote:  The commands are quite different:
DOLIST works with one element from several lists.
DOSUBS works with several elements within the same list
MAP works with a single element of a single list, but fully recursive (goes inside lists of lists and preserves the structure).

Yes, but my point was that DOLIST, DOSUBS, and MAP all appear to work similarly in the special case where you are working with one list, one element at a time (ie. n=1).

If there's a need to utilize the loop index for that type of scenario, that seemingly limits the choice to DOSUBS. But if that need doesn't exist, any of the three could be used.

I just ran a couple quick trials of a simple test of all three of these commands with the same subprogram:
Code:
D01
\<<
  1 100 FOR x
    x
  NEXT
  100 \->LIST
\>>

DoMAP
\<<
  MAP
\>>

DoDOLIST
\<<
  DOLIST
\>>

DoDOSUBS
\<<
  DOSUBS
\>>

Test
\<<
  D01 \<< \v/ \>> 'DoMAP' TEVAL NIP
  D01 \<< \v/ \>> 'DoDOLIST' TEVAL NIP
  D01 \<< \v/ \>> 'DoDOSUBS' TEVAL NIP
\>>

A typical run gave these results on my 50g (approx. mode):
MAP: 1.0255
DOLIST: 0.4794
DOSUBS: 0.4556

As John indicated, MAP appears to be much slower. With this (albeit simple) test, MAP took over twice as long to produce the same results as the other two. Interestingly, DOSUBS seemed to have a very slight edge over DOLIST. But the difference was very minor and may not even be consistent over multiple runs.

That being the case, I have to wonder if the only time you'd really want to use MAP is when you need the recursive processing of lists that include other lists. Any other scenario for MAP would seemingly perform better with either of the other two commands.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzles: processing lists! - DavidM - 04-25-2017 03:01 AM



User(s) browsing this thread: 2 Guest(s)