all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: dalanicolai <dalanicolai@gmail.com>
To: Emacs Devel <emacs-devel@gnu.org>
Subject: Weird let behavior (and where to ask for support)
Date: Sun, 23 Jan 2022 01:33:07 +0100	[thread overview]
Message-ID: <CACJP=3k2HcsXR-K70uSoFHU350ev4-boA19Zf+mN2XqdgANsjQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1799 bytes --]

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?

[-- Attachment #2: Type: text/html, Size: 2538 bytes --]

             reply	other threads:[~2022-01-23  0:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-23  0:33 dalanicolai [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-01-23  2:51 Weird let behavior (and where to ask for support) Pierpaolo Bernardi
2022-01-23  4:27 ` Stefan Monnier
2022-01-23 10:26   ` dalanicolai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACJP=3k2HcsXR-K70uSoFHU350ev4-boA19Zf+mN2XqdgANsjQ@mail.gmail.com' \
    --to=dalanicolai@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.