help-gnu-emacs
[Top][All Lists]
Advanced

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

unused lexical variable in `cl-loop'


From: Emanuel Berg
Subject: unused lexical variable in `cl-loop'
Date: Tue, 27 Sep 2022 22:43:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

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 via email to

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