Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Linked lists considered harmful

Name: Anonymous 2009-10-10 20:46

  ↑    slava_pestov 4 points 5 hours ago [-]
  ↓    A perfect illustration of why single linked lists are simply the wrong data structure in
        99% of cases. Just use arrays and you won't have to choose between tail recursion, and
        front-to-back iteration order.
        permalink report reply

Name: Anonymous 2009-10-11 15:37

>>38
Here's a factoring challenge for you. I have this Forth code here (modified from a piece of Forth code I wrote some time ago, works on GForth) that makes extensive use of local variables. If you can turn this into a readable, variable-free, more finely factored code, I will totaly believe everything you said about the concatenative approach. I would ask that you keep it in Forth so we could test the advantages of concatenativity alone.

: exchange ( addr1 addr2 -- ) dup c@ rot dup c@ -rot c! swap c! ;
\ exchanges the contents of two character addresses.

: permuts_do_loop { set set_size permut permut_size action -- }
   set permut permut_size + = if
       permut permut_size action execute
   else
      set_size 1- dup to set_size for
         set dup i chars + 2dup exchange
         set char+ set_size permut permut_size action recurse
         exchange
      next
   endif
;

: permuts_do ( set set_size permut_size action ) 2>r over 2r> permuts_do_loop ;

s" 0123456789" 2constant 0_to_9

0_to_9 4 :noname type cr ; permuts_do
0_to_9 type cr bye

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List