From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.help Subject: Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'? Date: Sat, 9 Jan 2021 15:02:08 +0100 Message-ID: References: <868s92ntez.fsf@x201.butler.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6406"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Leo Butler Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 09 15:02:47 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kyEpL-0001Y9-9s for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 09 Jan 2021 15:02:47 +0100 Original-Received: from localhost ([::1]:43220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyEpK-0001mB-CE for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 09 Jan 2021 09:02:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyEp0-0001lf-0q for help-gnu-emacs@gnu.org; Sat, 09 Jan 2021 09:02:26 -0500 Original-Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:35157) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kyEov-0004Lq-L7 for help-gnu-emacs@gnu.org; Sat, 09 Jan 2021 09:02:25 -0500 Original-Received: by mail-oi1-x231.google.com with SMTP id s2so14880783oij.2 for ; Sat, 09 Jan 2021 06:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=MaWhsEQwTKK1XUod29ogdBbAuwL9FwevTRGrBcXzxI8=; b=obwmC5wNpWA4iaFa+iifmNxYIG+hCXvQn+Ckzk0U1mYZon//vQZaZZJ97ujjKCxvab WzJ61K36nUol2Emm5E6WluVuDy6LlcRQ+AeUVQCwa9U8E8u4lbFdF3Y5TRB3eDAmU4eT YoMg4N+vpzwbLPP64fe189ZoiPOIXDS6hJCScCgOZyEhZbiMU5EOC0X5tvVjNv8RD17K x9d/VZyeVBunXA7wstU6nX+d0ia508prBiWGHTBPR+Ipl81jhe6jbWnSF9nD5jcRw5Ln A5PkeM/Wkhex+eiAnDLx08S0wt7A7+0AKM5dN24P+5LaYupnNaVz5OhdUXJ5Zp6LvKbG Vu7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=MaWhsEQwTKK1XUod29ogdBbAuwL9FwevTRGrBcXzxI8=; b=Bu3/iNIR6glXXANcLMoAzY+5TvHhIugEvdhEcg/2MYr2vWYiSjbwwLFGmX0aN037fJ ffwCdxcW2mlHSFMwpULcUx6g0LV04+r0fCSCWzkv2uq8r2Z00b61dKs2d/uQ3p0bWydT J1PWGdMv1OFLarVz5/a+FCXhIW7i6ZndNwQwe0Le/jadb3P5u31WifeEl3Q4S4SrK6ra BM6odpYTxxQ+EdxpWhKRNtCUlqe6aU9FXHnFRr0yhgr4k7VgB7NZIkKmQKOZCv3QYWIh HLp3at/xDhmcKnSZNuhmUinWZqys9hz78+Hq3XjnPTMddLlSdyU4NK/vU2WwU0Rg8pma C/CA== X-Gm-Message-State: AOAM530mHd8h8BZIbPuAy6qCY/WoXoGaM43DVzxpb4SZbWJ9rVyfRfkx bPWJEN1NrPIRfJoQTSEPW35V6xyGjk7/Qqhme7A= X-Google-Smtp-Source: ABdhPJwM+Vgw8ZzVshS1EBhMiiGlegYk5wwdPD4BJHA6Asr/CmZzGhmo2rtmYjEp/YJbCfR1KQBfF0Po+k1i8NKYyhc= X-Received: by 2002:aca:3784:: with SMTP id e126mr5241263oia.170.1610200939640; Sat, 09 Jan 2021 06:02:19 -0800 (PST) In-Reply-To: <868s92ntez.fsf@x201.butler.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::231; envelope-from=p.stephani2@gmail.com; helo=mail-oi1-x231.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:127130 Archived-At: Am Sa., 9. Jan. 2021 um 14:30 Uhr schrieb Leo Butler : > > Stefan, > > I wonder why the lexical-binding version of dotimes is not implemented > like: > > #+begin_src emacs-lisp > (let* ((start 0) (end (nth 1 spec)) (counter (gensym)) > (body (subst counter (car spec) body))) > `(let ((,counter ,start)) > (while (< ,counter ,end) > ,@body > (setq ,counter (1+ ,counter))) > ,@ (cddr spec)))) > #+end_src That would be a semantically different operation. `dotimes' guarantees that the counter variable is let-bound within each iteration. That means that the macro expansion needs to contain something like (let ((VAR ...)) BODY) This distinction becomes relevant if BODY modifies VAR or captures it in a closure. > I am familiar with the comment in subr.el about uninterned symbols, but > TBH, I don't have a sense of where the performance penalty might be > of any significant size. The uninterned vs. interned distinction is unrelated. `dotimes' chooses to use an interned symbol as a micro-optimization, but it doesn't affect its behavior. > > Leo > > Jean Louis writes: > > > ******************************************************** > > Caution: This message was sent from outside the University of Manitoba. > > ******************************************************** > > > > * Stefan Monnier [2021-01-08 10:16]: > >> > Only it is not relevant to macro or function that is documented to > >> > work, but then again it gives warnings for `n' and not for `return' = as > >> > in above example. > >> > >> Not sure what you mean by "documented", but `C-h f dotimes` says: > >> > >> dotimes is a Lisp macro in =E2=80=98subr.el=E2=80=99. > >> > >> (dotimes (VAR COUNT [RESULT]) BODY...) > >> > >> Probably introduced at or before Emacs version 21.1. > >> > >> Loop a certain number of times. > >> Evaluate BODY with VAR bound to successive integers running from 0= , > >> inclusive, to COUNT, exclusive. > >> > >> Finally RESULT is evaluated to get the return value (nil if > >> RESULT is omitted). Using RESULT is deprecated, and may result > >> in compilation warnings about unused variables. > >> > >> Notice the last sentence. > > > > Now I do notice it. > > > > I do switch to `while' and mapping functions rather. > > > > Jean >