Linked Questions

1 vote
1 answer

Setq doesn't work [duplicate]

Glad that the title got your attention :D I have this little snippet that's driving me crazy: (defvar cache '(nil . nil)) (defun init-cache () (setq cache '(nil . nil))) (defun save (value) (...
R1ck77's user avatar
  • 113
2 votes
2 answers

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.6k
1 vote
1 answer

Local variable's state mutated across function calls [duplicate]

I was surprised to discover that a local variable can have it's state modified across function invocations. Consider the following example. (defun example-mutable () (let ((x '("the" "quick" "...
dpritch's user avatar
  • 445
1 vote
0 answers

why does this function keep updating the same result? [duplicate]

I am trying to do the following exercice: Given a DNA string, compute how many times each nucleotide occurs in the string. DNA is represented by an alphabet of the following symbols: 'A', 'C', ...
little-dude's user avatar
2 votes
1 answer

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,576
3 votes
1 answer

Why is this function not pure

I just spent a significant amount of time debugging an issue that boils down to the following: (defun my-new-alist () `((x . nil))) (setq a (my-new-alist)) (setq b (my-new-alist)) (push 1 (alist-...
Clément's user avatar
  • 3,995
3 votes
1 answer

What is the difference between these two lists?

I'm reading An Introduction to Programming in Emacs Lisp by Robert J. Chassell. When the book is introducing setcar, it points out that when we use this function to a list, the list should be ...
Lluvio Liu's user avatar
0 votes
1 answer

Unexpected behavior when updating alist

Question: The code is below, the contents of the list myList were copied in the debugger. (let* ((myList '(("Concept Index" ("Файл" "/home/alamd/example/funEl/expirement/...
uanr81's user avatar
  • 169
1 vote
1 answer

Strange behavior pushing an element into the car of a list using a function

The following is a very simple function called my-function which begins by setting the global variable L to be the list containing nil. The next step is to modify (car L), a.k.a. nil, by pushing ...
Ruy's user avatar
  • 839
0 votes
1 answer

Function arguments in quoted lists [duplicate]

First example: (defun first (a) '(a 1)) (first 2) => (a 1) Second example: (defun second (b) (+ b 1)) (second 1) => 2 How can I get (2 1) with (first 2)?
Valeriy's user avatar
  • 387