all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: unused lexical variable in `cl-loop'
Date: Tue, 27 Sep 2022 22:43:50 +0200	[thread overview]
Message-ID: <8735cclf95.fsf@dataswamp.org> (raw)

This code works but the byte-compiler says the lexical
variable 'num' is unused on the first two occasions it occurs
in the code.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/math.el

(require 'cl-lib)

(defun interval (&optional min max)
  (interactive "nmin: \nnmax: ")
  (or min (setq min 0))
  (or max (setq max 9))
  (unless (<= min max)
    (error "Bogus interval") )
  (cl-loop for i from min to max
           with num = ()
           collect i into num
           finally return num) )

;; (interval 10 5)
;; (interval)
;; (interval 19 99)

;; Warning: Unused lexical variable `num'
;; Warning: Unused lexical variable `num'

I don't know if that makes sense, it doesn't look like it,
however it gave me an idea:

(defun interval (&optional min max)
  (interactive "nmin: \nnmax: ")
  (or min (setq min 0))
  (or max (setq max 9))
  (unless (<= min max)
    (error "Bogus interval") )
  (cl-loop for i from min to max collect i) )

and indeed that works just as well and there isn't a warning.

So that's good ... but why nothing happens with 'num' in the
first attempt I wonder?

-- 
underground experts united
https://dataswamp.org/~incal




             reply	other threads:[~2022-09-27 20:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 20:43 Emanuel Berg [this message]
2022-09-28 10:58 ` unused lexical variable in `cl-loop' Michael Heerdegen
2022-09-28 12:40 ` Felix Dietrich
2022-09-30 22:59   ` Emanuel Berg
2022-10-01 15:10     ` Stefan Monnier via Users list for the GNU Emacs text editor

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=8735cclf95.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@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.