Questions tagged [list]

is for the list object in Lisp programming. A list represents a sequence of zero or more elements. Emacs Lisp relies extensively on the list data structure; it is a fundamental building block. Emacs provides many facilities for building, modifying, extending, and efficiently handling list data structures.

Filter by
Sorted by
Tagged with
13 votes
1 answer
652 views

Why does a constant in `let` change with repeated calls? [duplicate]

Say we have such a foo function: (defun foo (e) (let ((lst '(a b c))) (delq e lst))) Then we use it in following way (sequentially evaluating one by one): (foo 'c) ; => (a b) (foo 'b) ; =&...
cutejumper's user avatar
9 votes
1 answer
2k views

When to use quote for lists? Modifying quoted lists in Elisp

The Common Lisp Hyper Spec says: The consequences are undefined if literal objects (including quoted objects) are destructively modified. This is further motivated at the Constant Modification ...
Tobias's user avatar
  • 33.1k
2 votes
2 answers
299 views

Evaluating symbol in function arguments affected by destructive operations?

While evaluating a function call, the arguments is from left to right. For example, (let ((x '(1 2 3))) (list (nreverse x) x)) ;; => ((3 2 1) (1)) The first argument (nreverse x) evaluates to (...
xuchunyang's user avatar
  • 14.5k
4 votes
2 answers
576 views

How can I paste paragraph not to interrupt numbers in list org mode?

In list environment, after I copy several paragraphs, the next item number will change into number 1, How can I deal with that? For example, 1. aaa 2. aaa 3. aaa bbb <---this is what I copied ...
yuxuan's user avatar
  • 781
2 votes
1 answer
292 views

Change level into list in org mode

I have following text which are expressed in level 5 ***** It's better to be first than it is to be better. ***** The basic issue in marketing is creating a category you can be first in. It’s the law ...
yuxuan's user avatar
  • 781
39 votes
3 answers
21k views

What's the difference between push and add-to-list?

I've found that different packages in their installation instructions use either push or add-to-list (For example adding a directory to load-path) and I was wondering what the difference is and what ...
shadowthief's user avatar
15 votes
1 answer
2k views

Is '(a . b) really a list?

I'm really confused with the . notation. Is '(a . b) a list? (listp '(a . b)) returns t but when I want to know its length (length '(a . b)) gives an error Wrong type argument: listp, b. The same is ...
tom's user avatar
  • 283
9 votes
2 answers
177 views

Proper reinitialization of a list? What is happening under the hood?

I'm teaching myself some more elisp and have encountered the following problem: If I want to reset a list variable it won't get updated after the first evaluation. Here is some example code: (defun ...
clemera's user avatar
  • 3,441
8 votes
2 answers
3k views

add-to-list vs add-hook?

What is the difference between add-to-list vs add-hook? For example I see in progmodes/make-mode.el: (add-hook 'completion-at-point-functions #'makefile-completions-at-point nil t) ...
gavenkoa's user avatar
  • 3,422
8 votes
5 answers
1k views

Report duplicates in a list?

Q: how do I get only the duplicate elements in a list? delete-dups (and cl-delete-duplicates) deletes all duplicate elements from a list: (delete-dups '(a b c c d d)) ; => '(a b c d) ...
Dan's user avatar
  • 32.9k
5 votes
0 answers
276 views

Structure-preserving copying of sequences

The form (cl-copy-tree TREE t) returns a deep-copy of a sequence TREE. The the Common Lisp Hyper Spec explains that copy-tree does not preserve circularities and sharing of substructures. I.e., even ...
Tobias's user avatar
  • 33.1k
4 votes
2 answers
832 views

Sort list by decreasing length of the strings

I have this list: (setq MYLIST '("J. Phys." "New. J. Phys." "J. Phys. Soc. Jap." "Phys. Plasmas")) How can I get a new list ordered by the decreasing ...
Gabriele Nicolardi's user avatar
3 votes
2 answers
258 views

What difference does it make changing the order of arguments to 'append'

I want to understand the implications of append's property that "All arguments except the last one are copied, so none of the arguments is altered." (from the Elisp manual) Say I have a list ...
Arch Stanton's user avatar
  • 1,627
3 votes
4 answers
567 views

How to mapcar uneven lists?

I am aware I can use mapcar to join 2 lists into pairs, however all the map functions seem to quit at the shortest list. This for example (cl-mapcar #'concat '("1" "2" "3" "4") '("a" "b" "c")) ...
Oly's user avatar
  • 593
3 votes
1 answer
233 views

What has replaced elib?

Looking for some data structures for elisp, I came across this. But then this warns me off -- without specifying exactly what replaces elib. So where do I get packages to do doubly linked lists?
147pm's user avatar
  • 2,957
2 votes
3 answers
507 views

Replace element in a list / add in case of absence, with custom test/key functions

add-to-list doesn't refresh item, it only checks for existence of item by equal or custom comparison function: (add-to-list 'tramp-methods '("gssh" (tramp-login-program "gcloud ...
gavenkoa's user avatar
  • 3,422
2 votes
2 answers
151 views

How do I get a return of multiple strings from a list?

I want this ("start" "--color=always" "--exclude=*pdf" "end") but I am getting this ("start" ("--color=always" "--exclude=*pdf") &...
ritchie's user avatar
  • 149
2 votes
1 answer
686 views

how to specify an Cyclic list in lisp?

How to specify a list, which's last element is referring to the first element? By specify I mean, for example, how to write a setq statement with this list. I have seen this in the documentation, ...
jue's user avatar
  • 4,556
2 votes
1 answer
631 views

how to parameterize prompt for interactive/command?

background I had elisp code (in this very small git repo) like (defun bulk-replace-file (filepath) (interactive "FPath to file to bulk-replace: ") (bulk-replace-file-non-interactive filepath) ) ...
TomRoche's user avatar
  • 622
1 vote
2 answers
108 views

Test whether all elements/symbols of a list are the same (eq)

Project: (1) Push every new this-command onto a list containing any previously pushed this-command. (2) Limit the list to a variable length (e.g., 3 or 5), and chop off the oldest. (3) Compare ...
lawlist's user avatar
  • 19.1k
1 vote
2 answers
1k views

Dolist not modifying the list

I'm trying to prepend each substring of split-string with numbering (1.,2.,3.,..) then return all the substrings concatenated with a newline (defun japanese-get-definition (dictentry) "Get a ...
irregular's user avatar
  • 1,002
1 vote
2 answers
509 views

Is there a way to spread a list like in Typescript or Golang?

I have a variable with some common values between dap-mode debug templates and I want to use that variable along with other cons elements for :environment-variable in languages like Golang or ...
shackra's user avatar
  • 2,772
1 vote
2 answers
379 views

How to subtract 1 from the nth element of a list of numbers?

How do I subtract 1 from the second element of the list (3 6)? (setq x '(3 6)) (- (nth 1 x) 1) The above quote does the math but does not return a modified list.
Sati's user avatar
  • 775
1 vote
1 answer
334 views

Replacing autoref command format specification in auctex's font-latex-match-reference-keywords-local

With some help I have redefined the autoref command to take an optional argument, see https://tex.stackexchange.com/questions/428229/autoref-with-optional-argument-text-in-generated-link Now I am ...
yogik's user avatar
  • 13
1 vote
2 answers
99 views

Why changing the value of this variable via add-to-list is not working?

Usually, I do the following to change a variable's value: 1 - I execute the command set-variable 2 - I pick cider-shadow-cljs-command 3 - I tweak the value changing it to be "shadow-cljs" It ...
Pedro Delfino's user avatar
0 votes
1 answer
126 views

Any existing function to fix comma-separated list in parens-pair?

I am looking a way to programatically fix invalidly formatted code for programming languages that use relatively simple list expression of elements separated by commas (ie, not in C++). For example I'...
PRouleau's user avatar
  • 796
0 votes
1 answer
95 views

Custom function to map through nested lists sorting by time-stamp

In the following example, please assume that we are using time-to-seconds to convert each times-stamp into a decimal representation. I have already converted the time-stamps to seconds in this ...
lawlist's user avatar
  • 19.1k
-1 votes
2 answers
143 views

Web scraping traversal using dom.el, pcase error: Unknown pattern

I would like to traverse the dom tree, extract the text and build a list after visiting each node. Implementing the recursion with the help of text-tag function returned an unknown pattern error. The ...
alexander's user avatar
  • 133
-1 votes
2 answers
138 views

Add a number to every item in list

How do I add a number, say 2, to every item in a list? (setq x '(1 2)) (+ 2 x) (mapcar '2+ x) (loop for i in x do (+ 2 i)) (dolist (i x) (+ 2 i)) None of the above work.
Sati's user avatar
  • 775
-3 votes
1 answer
100 views

Adapting list according to array

I want to construct a list of lists using the function pmchart (pmchart '("Peter" "John") [3 2] 5) to produce '(("Peter" "xxxxx" "xxxxx" "xxxxx&...
Dilna's user avatar
  • 1