![]() ![]() In the appendix is a function for checking if two lists share structure. is nil) does NOT guarantee that the two list do not share structure. This is why we sometimes need to watch out for lists that share structure with other lists, and there are many functions that return a list that may share structure with one of its arguments. So doing something to the list x can affect the list y. If we modify the list x by doing 2 (setf (cdr (cddr x)) something), we change the cdr of the last-to-second cons cell, and depending on what something is, this can make x a longer list or a shorter list or an improper list. And that affects the list y too because the last-to-second cons cells for the list x and that for the list y are the same cons cell. If we modify the list x by doing (setf (elt x 2) something), we change the element of x at index 2 (in the sense of new designation), that is, we change the car of the last-to-second cons cell. The second kind comes from writing self-evaluating forms. The first kind comes from writing quoted forms. (equal (list (list 0 1 ) (list 2 3 ) (list 4 5 ) ) ' ( (0 1 ) (2 3 ) (4 5 ) ) two ways of writing nested lists expecting the below line to evaluate to 11. Expecting the above line to evaluate to 3 is like (length (0 11 22 ) ) ERROR: 0 is not a function. A literal list should be quoted (with a single quote) in general in code. Large part of this post draws from that chapter. Nevertheless, if you see something that’s elisp-only that’s not explicitly stated as being elisp-only, feel free to point out.Ĭredits: Chapter 12 of Practical Common Lisp was of huge help for me to eliminate all the confusion I had on this subject some time ago. Since this post is part of the Living with Emacs Lisp series, I am mainly speaking to elisp beginners. ![]() This post assumes the reader have read the previous article about uniform reference semantics and its implications (for container objects and function parameter passing). To translate some snippets into Common Lisp, see the Common Lisp note at the end. Nevertheless, everything that is said on this post also applies to Common Lisp, not just elisp, unless stated otherwise. For beginners to be able to use those functions without falling to common mistakes, it is crucial to know the meaning of phases like “modify a list”, “this list shares structure with that list”, “destructive function”, “literal list”.Īll Lisp snippets in this post are in elisp, unless stated otherwise. Since functions and macros for manipulating lists can be easily found by searching the Internet, instead of listing all those helpful functions, this post will focus more on making you prepared for terminology and gotchas surrounding Lisp lists. Goal of this post is to be some small introduction to lists in Lisp. Do this post apply to alists and trees as well? destructive functions and non-destructive functions ![]() check for empty list, non-empty list, list Use of literals and aggregation variables, you can project newįields or project existing fields with new values. Starting in MongoDB 4.4, with the use of aggregation ![]() Specifies the value of the projected field. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |