Hw04 题解 (UCB CS61A@2021 Fall)
Mobiles
Q2: Weights
Implement the
planet
data abstraction by completing theplanet
constructor and thesize
selector so that a planet is represented using a two-element list where the first element is the string'planet'
and the second element is its size.
从问题的描述中我们可以知道什么是 planet
. 就是一个长度为 2 的 list
, 内容是 ['planet', size]
. 可以参考 mobile
函数, 这两个函数的代码是很类似的