[plt-scheme] idiomatic way to split a list into first, middle, last?
> a) prioritize readability:
>
> (let* ([first (car l)]
> [middle (reverse (cdr (reverse (cdr l))))]
> [last (car (reverse l))])
> `(,(first-proc first) ,@(map middle-proc middle) ,(last-proc last)))
>
> ... This one seems grotesquely inefficient, even though
> 1) it's not asymptotically any slower, and
> 2) you can get rid of one of the three calls to 'reverse'.
Even more readable, though with the same inefficiencies:
(require (lib "list.ss" "srfi" "1"))
(let* ([initial (first ls)]
[middle (drop-right ls 1)]
[final (last ls)])
`(,(p1 initial) ,@(map p2 middle) ,(p3 final)))
Dave