emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird let behavior (and where to ask for support)


From: Pierpaolo Bernardi
Subject: Re: Weird let behavior (and where to ask for support)
Date: Sun, 23 Jan 2022 03:51:07 +0100

You are modifying the constant '(0). Modifying constants has an unspecified effect, one manifestation of which you are observing.

Change '(0) to (list 0).



Il giorno 23 gennaio 2022, alle ore 01:34, dalanicolai <dalanicolai@gmail.com> ha scritto:


I am trying again to improve/clean up the implementation of continuous scroll in doc-view.
 But I find some strange behavior, for which I have no explanation.

 So let me first explain the essence of the problem. I am using the following code, in a file with lexical-binding enabled (in case that would matter).
I will provide the full function later also, but here is the essence:

 (defun book-image-positions (image-sizes)
  (let ((positions '(0)))
    (message "POS %s" positions)))

I really use the variable name 'positions' only within this function (I bind the result to
a variable named 'image-positions'
I would expect that 'positions' would always get initialized as '(0).
But when I print the value after the let, then it shows me a large list.
I guess I am missing something here, and also I guess you probably
know what it is.

A little more context, I have a list with image-sizes (heights), and I am creating
a list with image positions from it.  For that I am using the following function
(incl. quite some print forms for debugging).

 (defun book-image-positions (image-sizes)
  (let ((sum 0)
        (positions '(0)))
    (print sum)
    (message "POS %s" positions)
    (dolist (s image-sizes)
      (setq sum (+ sum (cdr s)))
      (print (push sum positions)))
    (message "RES %s" (reverse positions))
    (nreverse positions)))

this function gets called multiple times and 'positions' does have the '(0) value the first time.

Then finally, I was trying to search for some related issue in the devel archive, but the
results always get 'cut off', because there are too many search results. Also, I think
users will more likely be able to find the question and answer on stack overflow, so
would you agree it is often best to ask these kind of 'elisp' questions there?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]