guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Efficiency of `map` (was: [PATCH] On Hurd, don't use not implemented mad


From: Stefan Monnier
Subject: Efficiency of `map` (was: [PATCH] On Hurd, don't use not implemented madvise())
Date: Thu, 08 Jun 2017 13:27:05 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

>   (define (map f l)
>     (if (pair? l)
>         (cons (f (car l))
>               (map f (cdr l)))
>         '()))
>
> whereas we used to have to write code like this in order to support long
> lists without overflowing the stack:
>
>   (define (map f l)
>     (let loop ((l l) (out '()))
>       (if (pair? l)
>           (loop (cdr l) (cons (f (car l)) out))
>           (reverse out))))

Ignoring stack usage, is the first version faster or slower than the second?
[ Or is the speed difference negligible?  ]

How 'bout using a side-effecting `reverse!` (like Lisp's nreverse)?


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]