Programming/lisp2013. 1. 3. 21:25
난해한(!) 명령어중에 하나로 car / cdr이라는 lisp 명령어가 있다.
car은 first에 대응되며 list의 가장 처음 내용만 보여주고
cdr은 rest에 대응되며 list의 처음것을 제외한 내용을 보여준다.

1> (car '(1 2 3))
1                
1> (cdr '(1 2 3))
(2 3)
1> (rest '(1 2 3))
(2 3) 

return the car of a list node
(car <expr>)

May be used as a place form.

<expr> the list node
returns the CAR of the list node


return the cdr of a list node
(cdr <expr>)

May be used as a place form.

<expr> the list node
returns the CDR of the list node

all cxxr combinations
(cxxr <expr>)
all cxxxr combinations
(cxxxr <expr>)
all cxxxxr combinations
(cxxxxr <expr>)

May be used as place forms when common2.lsp loaded.

a synonym for car
(first <expr>)
a synonym for cadr
(second <expr>)
a synonym for caddr
(third <expr>)
a synonym for cadddr
(fourth <expr>)
fifth list element
(fifth <expr>)
sixth list element
(sixth <expr>)
seventh list element
(seventh <expr>)
eighth list element
(eighth <expr>)
ninth list element
(ninth <expr>)
tenth list element
(tenth <expr>)
a synonym for cdr
(rest <expr>)

May be used as place forms when common2.lsp loaded.  fifth through tenth defined in common2.lsp. 

Etymology

Lisp was originally implemented on the IBM 704 computer, in the late 1950s. The 704 hardware had special support for splitting a 36-bit machine word into four parts, an "address part" and "decrement part" of 15 bits each and a "prefix part" and "tag part" of three bits each.

Precursors to Lisp included functions:

  • car (short for "Contents of the Address part of Register number"),
  • cdr ("Contents of the Decrement part of Register number"),
  • cpr ("Contents of the Prefix part of Register number"), and
  • ctr ("Contents of the Tag part of Register number"),

each of which took a machine address as an argument, loaded the corresponding word from memory, and extracted the appropriate bits.

http://en.wikipedia.org/wiki/CAR_and_CDR]

'Programming > lisp' 카테고리의 다른 글

만들면서 배우는 리스프 프로그래밍  (2) 2013.01.09
lisp 전역변수 / 지역변수  (0) 2013.01.09
lisp 반복문  (0) 2012.12.31
clisp  (0) 2012.12.29
lisp 기본함수  (0) 2012.12.29
Posted by 구차니