[racket] Tabulate from build-list

From: Sean Kemplay (sean.kemplay at gmail.com)
Date: Mon Jul 30 16:10:52 EDT 2012


I am looking at the exercise from htdp 1e on building the tabulate
function from build-list.

Would I be on the right track that I need to create a function to
reverse the result of (build-list (+ n 1) f) to do this?

the function this is to emulate -

;; tabulate : (x -> y) x ->  (listof y)
;; to tabulate f between n
;; and 0 (inclusive) in a list
(define (tabulate f n)
    [(= n 0) (list (f 0))]
      (cons (f n)
	(tabulate f (sub1 n)))]))

Using build-list
;; build-list : N (N  ->  X)  ->  (listof X)
;; to construct (list (f 0) ... (f (- n 1)))
(define (build-list n f) ...)


Posted on the users mailing list.