(define p1 '(4 "the" "dog" "chewed" "the" "rug"))
(define p2 '(79 "on" "the" "rug" "slept" "the" "dog"))
(define p3 '(32 "the" "rug" "rats" "slept" "on"))
(define p4 '(42 "the" "meaning" "of" "life"))
给定列表p1-p4我想编写一个名为get-page-number的函数,该函数将从列表中提取数字。例如:
(get-page-number p2)
将返回79
然后我需要编写一个名为get-words的函数来摆脱数字并返回字符串。例如:
(get-words p1)
会返回“the”“dog”“chewed”“the”“rug”
答案 0 :(得分:1)
无需创建功能。 car
和cdr
会这样做。
(define get-page-number car)
(define get-words cdr)
(get-page-number p3) ; ==> 32
(get-words p3) ; ==> ("the" "rug" "rats" "slept" "on")
答案 1 :(得分:0)
试试这个:
(define get-page-number car)