热度 2| |
Modifying Lists
The following functions operate on variables without changing their value or creating new
variables.
以下函数在操作变量时不会改变它们的值或创建新的变量。
Coordinates
An xy coordinate is represented by a two-element list. The colon (:) binary operator builds a
coordinate from an x value and a y value.
一个xy坐标被表示为一个由两个元素组成的列表。冒号 (:) 二元操作符将一个x值和一个y值构建成一个坐标。
xValue = 300
yValue = 400
aCoordinate = xValue:yValue => ( 300 400 )
The functions xCoord and yCoord access the x coordinate and the y coordinate.
函数xCoord和yCoord分别访问x坐标和y坐标。
xValue = 300
yValue = 400
aCoordinate = xValue:yValue => ( 300 400 )
xCoord(aCoordinate) ==>300
yCoord(aCoordinate) ==>400
car(aCoordinate) ==>300
cadr(aCoordinate) ==>400 ; The xCoord and yCoord functions are aliases for The car and The cadr functions.
1)You can use the single quote (') operator or list function to build a coordinate list.
2)You can use the car function to access the x coordinate and car( cdr ( … ) ) to access
the y coordinate.
alias /ˈeɪliəs/ n 别名;
Coordinate /kəʊˈɔːdɪneɪt , kəʊˈɔːdɪnət/ n 坐标;
represent /ˌreprɪˈzent/ v 代表,表示;
colon /ˈkəʊlən/ n 冒号
注:binary operator 二元操作符
在编程中,二元操作符是指需要两个操作数才能执行操作的运算符。例如,在表达式1 + 2中,“+”是一个二元操作符,操作数为1和2。另外,冒号“:”也是一个二元操作符,它需要两个操作数来构建一个坐标,即x值和y值。
Bounding Boxes
A bounding box is represented by a list of the lower-left and upper-right coordinates. Use the
list function to build a bounding box that contains 一个边界框用包含左下角和右上角坐标的列表表示。使用list函数构建一个包含……的边界框。
1)Coordinates specified with the binary operator (:).
bBox = list( 300:400 500:450 ) ==>((300 400) (500 450))
bBox = '(300:400 500:450) ==>((300:400) (500:450)) ;注意两个表达式的区别,带运算符的列表,不适合用单引号表示
2)Coordinates specified by variables.
lowerLeft = 300:400
upperRight = 500:450
bBox = list( lowerLeft upperRight ) ==>((300 400) (500 450))
You can use the single quote (') operator to build the bounding box if the coordinates are specified by literal lists.
bBox = '(( 300 400 ) ( 500 450 ))
Bounding boxes provide a good example of working with the car and cdr functions. Use any combination of four a’s (each a executes another car) or d’s (each d executes another cdr).
边界框是使用car和cdr函数进行操作的一个很好的示例。使用4个a(每个a执行另一个car)或d(每个d执行另一个cdr)的任意组合。
Using car and cdr with Bounding Boxes
aBox=list((x1:y1) (x2:y2)) ==>((x1 y1) (x2 y2))
car(aBox) ==> (x1 y1)
cdr(aBox) ==>(x2 y2)
caar(aBox) ==>x1
cadar(aBox) ==>y1
caadr(aBox) ==>x2
cadadr(aBox) ==y2
bind v 绑定;捆绑;系 bound/bound
bounding 形成…的边界
specify /ˈspesɪfaɪ/ 具体说明;明确规定;详述;详列
literal /ˈlɪtərəl/ adj 字面意义的;完全按原文的;缺乏想象力的