It is safe to assume that it is not tail recursive since the standard (RNRS, including the latest R7RS) doesn't require tail recursion modulo cons optimization.
That of course doesn't deny anyone from actually implementing TRMCO in their Scheme implementation so that your definition of map
, which is almost tail recursive (except for that cons
), really would become tail recursive. Such an implementation could achieve this by transforming your code to something similar to the code below:
#!r6rs
(import (except (rnrs) map)
(rnrs mutable-pairs))
(define (map fun lst)
(define result (cons 'head '()))
(let loop ((tail result) (lst lst))
(cond ((null? lst) (cdr result))
(else (set-cdr! tail (cons (fun (car lst)) '()))
(loop (cdr tail) (cdr lst))))))
The transformation is pretty straightforward so I really don't see why Scheme implementations don't do it automatically, when Prolog does. It's less complex than what an implementation needs to do to support syntax-rules
or call-with-current-continuation
.