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.
17
questions
13
votes
1answer
526 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) ; =&...
9
votes
1answer
679 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 ...
2
votes
2answers
199 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 (...
2
votes
1answer
252 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 ...
4
votes
2answers
445 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
...
15
votes
1answer
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 ...
9
votes
2answers
140 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 ...
-1
votes
2answers
51 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.
5
votes
0answers
177 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 ...
3
votes
1answer
197 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?
2
votes
1answer
300 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)
)
...
1
vote
3answers
64 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 ...
1
vote
2answers
326 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 ...
1
vote
2answers
198 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.
1
vote
2answers
73 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 ...
1
vote
1answer
421 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, ...
0
votes
1answer
82 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 ...