-
Notifications
You must be signed in to change notification settings - Fork 4
/
05-2-pizza.rkt
executable file
·40 lines (34 loc) · 1.41 KB
/
05-2-pizza.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;; 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-beginner-reader.ss" "lang")((modname 05.1-replace-anchovies-with-onions) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;; Data Definitions:
;; A Topping is a String.
;; A Pizza is a ListOfTopping
;; interp: a pizza is a list of toppings, listed from top to bottom
;; pizza-fn : Pizza -> ??
; Given a Pizza, produce ....
;; (define (pizza-fn p)
;; (cond
;; [(empty? p) ...]
;; [else (... (first p)
;; (pizza-fn (rest p)))]))
;; Examples:
(define plain-pizza empty)
(define cheese-pizza (list "cheese"))
(define anchovies-cheese-pizza (list "anchovies" "cheese"))
;;; This is the original function definition, from the slides:
;; replace-all-anchovies-with-onions
;; : Pizza -> Pizza
;; RETURNS: a pizza like the given pizza, but with
;; anchovies in place of each layer of onions
;; STRATEGY: Use template for Pizza on p
(define (replace-all-anchovies-with-onions p)
(cond
[(empty? p) empty]
[else (if (string=? (first p) "anchovies")
(cons "onions"
(replace-all-anchovies-with-onions
(rest p)))
(cons (first p)
(replace-all-anchovies-with-onions
(rest p))))]))