;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname foldrr) (read-case-sensitive #t) (teachpacks ((lib "docs.rkt" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "docs.rkt" "teachpack" "htdp")) #f))) (define (foldrr op ys id) (if (null? ys) id (op (car ys)(foldrr op (cdr ys) id)))) (foldrr append '((1 2) (3 4)) '()) ; returns (list 1 2 3 4) (define (len z) (foldrr (lambda (x y) (+ 1 y)) z 0)) (len '(5 6 7)) ; returns 3 (len '(5 (6) ((7)))) ; returns 3 (foldrr + '(1 2 3 4 5) 0) ; returns 15 (foldrr * '(1 2 3) 1) ; returns 6 (map abs '(-1 2 -3)) ; returns (list 1 2 3) (define (foldll g ys u) (if (null? ys) u (foldll g (cdr ys) (g u (car ys))))) (foldll + '(1 2 3 4 5) 0) ; return 15 but computes it differently than foldrr