all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* unused lexical variable in `cl-loop'
@ 2022-09-27 20:43 Emanuel Berg
  2022-09-28 10:58 ` Michael Heerdegen
  2022-09-28 12:40 ` Felix Dietrich
  0 siblings, 2 replies; 5+ messages in thread
From: Emanuel Berg @ 2022-09-27 20:43 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-01 15:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-27 20:43 unused lexical variable in `cl-loop' Emanuel Berg
2022-09-28 10:58 ` 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

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.