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

Lisp and Scheme

Name: Anonymous 2007-03-08 8:14 ID:fc2iv5gF

Why is this shit still around? Didn't Haskell obsolete it 20 years ago?

Compare map:

 (define (map f lst)
   (let loop ((lst lst)
              (res '()))
     (if (null? lst)
       (reverse res)
       (loop (cdr lst)
             (cons (f (car lst)) res)))))

vs.

 map f []     = []
 map f (x:xs) = f x : map f xs

Name: Anonymous 2007-03-08 13:36 ID:fc2iv5gF

Okay here's a challenge to you Lisp heads then: write a function that takes a list of numbers X and an arbitrary list Y and splits Y into sublists the size of x1, x2, x3,...

in other words:
f [2,5,0,3] [1..15] == [[1,2],[3,4,5,6,7],[],[8,9,10],[11,12,13,14,15]]

here's the Haskell version:

f = foldr (\n r -> splitAt n >>> second r >>> uncurry (:)) return

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