-
Notifications
You must be signed in to change notification settings - Fork 0
/
233.rkt
75 lines (68 loc) · 2.07 KB
/
233.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;; 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-abbr-reader.ss" "lang")((modname 233ex) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
;; Exercise 233
;; ------------
;; Develop alternatives to the following expressions that use only list and
;; produce the same values:
;;
;; `(0 ,@'(1 2 3) 4)
;;
;; this table-like shape:
;;
;; `(("alan" ,(* 2 500))
;; ("barb" 2000)
;; (,@'("carl" " , the great") 1500)
;; ("dawn" 2300))
;;
;; and this third web page:
;;
;; `(html
;; (body
;; (table ((border "1"))
;; (tr ((width "200"))
;; ,@(make-row '( 1 2)))
;; (tr ((width "200"))
;; ,@(make-row '(99 65))))))
;;
;; Use check-expect to check your work.
;; -----------------------------------------------------------------------------
(check-expect
`(0 ,@'(1 2 3) 4)
; ==
(list 0 1 2 3 4))
(check-expect
`(("alan" ,(* 2 500))
("barb" 2000)
(,@'("carl" " , the great") 1500)
("dawn" 2300))
; ==
(list (list "alan" (* 2 500))
(list "barb" 2000)
(list "carl" " , the great" 1500)
(list "dawn" 2300)))
; List-of-numbers -> ... nested list ...
; creates a row for an HTML table from l
(define (make-row l)
(cond
[(empty? l) '()]
[else (cons (make-cell (first l))
(make-row (rest l)))]))
; Number -> ... nested list ...
; creates a cell for an HTML table from a number
(define (make-cell n)
`(td ,(number->string n)))
(check-expect
`(html
(body
(table ((border "1"))
(tr ((width "200"))
,@(make-row '( 1 2)))
(tr ((width "200"))
,@(make-row '(99 65))))))
; ==
(list 'html
(list 'body
(list 'table (list (list 'border "1"))
(list 'tr (list (list 'width "200")) (list 'td "1") (list 'td "2"))
(list 'tr (list (list 'width "200")) (list 'td "99") (list 'td "65"))))))