#lang racket ;; ------------------------------------------------------------------------ ;; The only multiplication operators we have for the this exercise: ;; ------------------------------------------------------------------------ (define half (lambda (n) (/ n 2))) (define double (lambda (n) (* n 2))) ;; ------------------------------------------------------------------------ ;; Russian peasant multiplication, with display of intermediate state. ;; Assumes m is a power of 2. ;; ------------------------------------------------------------------------ (define multiply (lambda (m n) (display-mn m n) (if (= m 1) n (multiply (half m) (double n))))) ;; ------------------------------------------------------------------------ ;; ... using a custom display procedure just for this exercise. ;; The function displayln, from your reading, would do, too. ;; (require "utilities.rkt") ;; (displayln m " " n) (define display-mn (lambda (m n) (display m) (display " ") (display n) (newline))) ;; --------------------------------------------------------------------------