;; 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-reader.ss" "lang")((modname week6_tu_full) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "htdp"))))) ; Q1: What does the following call to (g 5) evaluate to? (define (g x) (local [(define (g x) (* 4 x))] (g (+ x 1)))) (g 5) ; Three main ways to write templates for multiple complex arguments: ; 1) Use the template for one arg, other arg(s) "along for the ride" ; Example: append ; 2) For two args of the same type, process them in "lock-step" ; Example: list equality (see below) ; 3) Consider "more complex interleaving" of the templates ; Example: the intersect function from last week ; Q2: Write a function that takes two lists of numbers, and returns whether they ; are identical. You may assume the given lists have the same length. ; Do not use the built-in "equal?" function ; lists-same : list-of-numbers list-of-numbers -> boolean ; returns whether two lists of the same length are identical (define (lists-same lon1 lon2) (cond[(empty? lon1) true] [(cons? lon1) (and (= (first lon1) (first lon2)) (lists-same (rest lon1) (rest lon2)))] )) (check-expect (lists-same empty empty) true) (check-expect (lists-same (list 1 2 3) (list 1 2 3)) true) (check-expect (lists-same (list 1 2 3) (list 1 2 4)) false)