热度 10| |
Accessing Lists
Lists are stored internally as a series of branching decision points. Think of the left branch as pointing to the first element and the right branch as pointing to the rest of the list (further branch decision points). The car function follows the left branch and the cdr function follows the right branch.
列表在内部被存储为一系列分支决策点。可以将左分支视为指向第一个元素,右分支视为指向列表的剩余部分(更多分支决策点)。car函数遵循左分支,而cdr函数遵循右分支。
series /ˈsɪəriːz/ n 系列;连续;接连
branch /brɑːntʃ/ vt 分开;分岔
n 树枝;分支;分部;分行;分店;政府部门;分支机构;
further /ˈfɜːðə(r)/ adj 进一步的;更多的;附加的
adv 进一步;(空间距离)较远;(过去或未来)更久远;
vt 促进;增进
Retrieving the first element of a list (car)
car returns the first element of a list. car was a machine language instruction on the first machine to run Lisp. car stands for contents of the address register.
car函数返回一个列表的第一个元素。car函数在第一台运行Lisp的机器上是一条机器语言指令。car代表地址寄存器的内容。
number='(1 2 3)
car(number) ==>1
地址寄存器(Address Register)是一种特殊的计算机寄存器,它存储内存地址或指针。通常,cpu使用地址寄存器来访问和操作内存中的数据。地址寄存器可以直接对内存进行操作,提高了处理速度和效率。
例如,在程序执行过程中,CPU需要从内存中读取数据时,可以将该数据所在内存单元地址加载到地址寄存器中,然后使用该地址从内存中读取对应的数据。同样地,当需要往内存中写入数据时,CPU也可以使用地址寄存器来指定写入的目标地址。
不同的计算机架构和处理器有不同数量和类型的地址寄存器。在现代计算机体系结构中,地址寄存器已成为计算机架构中必不可少的重要组成部分之一。
Retrieve /rɪˈtriːv/ v 检索;取回;收回;检索操作;
instruction /ɪnˈstrʌkʃn/ n 用法说明;操作指南;指示;命令;吩咐;
stand for 代表,表示;容忍;
register /ˈredʒɪstə(r)/ vt 登记;注册;记录
n 登记簿;登记表;注册簿;声区
the address register 地址寄存器
Retrieving the tail of the list (cdr)
cdr returns a list minus the first element. cdr was a machine language instruction on the first machine to run Lisp. cdr stands for contents of the decrement register.
cdr函数返回一个列表除去第一个元素后的部分。cdr函数在第一台运行Lisp的机器上是一条机器语言指令。cdr代表递减寄存器的内容。
number'(1 2 3)
cdr(number) ==> (2 3) ;递减寄存器
在最早的Lisp机器中,递减寄存器(decrement register)是一个特殊寄存器,它用于记录当前列表结构中某个元素的位置。cdr操作将这个指针向前移动一位,即指向下一个元素。因此,cdr代表了递减寄存器的内容。在现代计算机体系结构中,递减寄存器已不再存在,其概念已经淡出了使用。
tail /teɪl/ n 尾;尾巴;有…尾巴的;尾部;后部;
decrement /ˈdɛkrɪmənt/ n 递减;消耗
the decrement register 递减寄存器
Retrieving an element given an index (nth)
nth assumes a zero-based index. nth(0 numbers) is the same as car( numbers).
nth函数假定索引从零开始。nth(0 numbers)与car(numbers)相同。
number=list(1 2 3 4)
nth(0 number) ==>1
car(number) ==>1
nth(2 number) ==>3
其中,zero-based index是指索引是从0开始计数的,而不是从1开始。例如,在列表中,第一个元素的索引为0,第二个为1,以此类推。而car函数是Lisp编程语言中的一种处理列表的函数,它返回列表的第一个元素。因此,当我们使用nth函数来获取列表的第一个元素时,可以使用索引值0,也可以使用car函数来获取。
Determining if a data object is in a list (member)
The member function cannot search all levels in a hierarchical list. It only looks at the top-level elements. Internally the member function follows right branches until it locates a branch point whose left branch dead ends in the element.
member函数无法搜索层次列表中的所有级别,它只查找顶级元素。在内部,member函数会按照右侧分支延伸,直到找到一个左侧分支死在该元素上的分支点。"
其中,层次列表是指由列表和子列表组成的多层嵌套结构,类似于树形结构。而member函数是Lisp编程语言中用于判断一个元素是否存在于列表中的函数,但是它只能查找列表的最外层,并且当列表中有多个相同元素时,只会返回第一个找到的元素。此外,当列表中的某个元素本身也是一个列表时,它不会递归地对子列表进行搜索,而只会在当前层面上进行搜索。内部细节解释了member函数在查找过程中如何遍历列表结构。
a=1 b=2 c=3 d=4
test=list(a b) ==>(1 2)
test1=list(a b c d test) ==>(1 2 3 4 (1 2))
test2='(a b c d) ==>(a b c d)
member(3 test1) ==>(3 4 (1 2)) ;如果嵌套结构在"member"检索的右边,是可以被搜索到的。
member(5 test1) ==> nil ;“member" 无法检测嵌套结构
member(2 test2) ==> nil ;“member" 无法检测变量
length(test) ==>2
length(test1) ==>5 ;子列表只能算一个
从上面的列子可以看出“member" 无法检测变量
determine /dɪˈtɜːmɪn/ v 决定;确定;测定;查明;准确算出;形成;支配;影响;
Counting the elements in a list (length)
length determines the length of a list, array, or association table
association /əˌsəʊsiˈeɪʃn/ n 协会;社团;联盟;联合;合伙;关联;交往;