mapi: similar to standard map in Scheme, but function has index of elements as second parameter.
;;; mapi: similar to standard map in Scheme, but function has index of elements as parameter. ;;; (define (mapi p l) (let loop ((l l) (i 0) (r '())) (if (pair? l) (loop (cdr l) (+ i 1) (cons (p (car l) i) r)) (reverse r)))) ;; Example: converting a binary number given as a list of binary digits. ;; (apply + (mapi (lambda (x i) (* x (expt 2 i))) '(0 1 1))) ;; => 6