emacs - why the change is in place for the list with elisp? -
i have question elisp. example:
(setq trees '(maple oak pine birch)) -> (maple oak pine birch) (setcdr (nthcdr 2 trees) nil) -> nil trees -> (maple oak pine)
i thought (nthcdr 2 trees)
returns new list - (pine birch)
, set list setcdr
expression, should not alter value of trees
. explain me?
if read documentation string nthcdr
, you'll see returns pointer "nth" "cdr" - pointer original list. you're modifying original list.
doc string:
take cdr n times on list, homecoming result.
edit wow, "pointer" seems stir confusion. yes, lisp has pointers.
just @ box diagrams used explain list construction in lisp (here's emacs's documentation on thing):
--- --- --- --- --- --- | | |--> | | |--> | | |--> nil --- --- --- --- --- --- | | | | | | --> rose --> violet --> buttercup
look @ arrows, they're .... pointing things. when take cdr
of list, 2nd box refers (aka "points" to), atom, string, or cons cell. heck, check out on wikipedia's entry car , cdr.
if feels improve phone call reference, utilize terminology.
cdr
not homecoming copy of refers to, confusing rnaer.
list emacs elisp cdr
No comments:
Post a Comment