From: steve-humphreys@gmx.com
To: moasenwood@zoho.eu
Cc: help-gnu-emacs@gnu.org
Subject: Re: Appending to a list
Date: Mon, 14 Dec 2020 06:28:31 +0100 [thread overview]
Message-ID: <trinity-f82aeb5a-ee8b-478a-bd66-a2fb4cbe2fe1-1607923711448@3c-app-mailcom-bs09> (raw)
In-Reply-To: <873609vvmg.fsf@zoho.eu>
> Sent: Monday, December 14, 2020 at 5:50 AM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Appending to a list
>
> steve-humphreys wrote:
>
> > I thought I could push element by element.
>
> You can, you can push whatever, if that data structure makes it
> more involved solve it for onee pilot case, then write a small
> `defun', put it there, and ever after just pass the single
> element to that.
>
> > I got inspiration from some discussions here that push is
> > more efficient and wanted to have a go. Yes, I do use push to
> > make the larger list. Have not thought about defvar before.
> > I have read that "setq" does not introduce a variable, but
> > I would need some explanation about that.
>
> It works with `setq' only without `defvar' the byte-compiler,
> which should always be used BTW, without it the byte-compiler
> will complain.
I have not understood the paragraph above.
> Comment-out the defvars in this
>
> (require 'cl-lib)
>
> (defvar bird-list-all)
> (defvar bird-list-1)
> (defvar bird-list-2)
>
> (setq bird-list-all '())
>
> (setq bird-list-1 '("Western jackdaw" "European goldfinch"))
> (setq bird-list-2 '("rook"))
>
> (cl-pushnew bird-list-1 bird-list-all) ; (("Western jackdaw" "European goldfinch"))
> (cl-pushnew bird-list-2 bird-list-all) ; (("rook") ("Western jackdaw" "European goldfinch"))
>
> and the byte-compiler will say
>
> geh.el:
> In toplevel form:
> geh.el:193:7: Warning: assignment to free variable ‘bird-list-all’
> geh.el:195:7: Warning: assignment to free variable ‘bird-list-1’
> geh.el:196:7: Warning: assignment to free variable ‘bird-list-2’
> geh.el:198:13: Warning: reference to free variable ‘bird-list-1’
> geh.el:198:25: Warning: reference to free variable ‘bird-list-all’
> geh.el:199:13: Warning: reference to free variable ‘bird-list-2’
>
> In more ambitious projects, like a package, e.g. [1], defvar
> should be used also to make available documentation, both in
> the code and for the on-line help which in practice is the same
> thing - Emacs is self-documenting, remember?
>
> Heh, not really, right? But still, do it.
>
> Anyway, don't rely too much on variables, defvar or no defvar.
> Better to rely on defuns and use `let' and `let*' there. IMO!
>
> [1] https://dataswamp.org/~incal/emacs-init/buc.el
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>
next prev parent reply other threads:[~2020-12-14 5:28 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-13 20:46 Appending to a list steve-humphreys
2020-12-13 21:03 ` Joost Kremers
2020-12-13 21:30 ` Óscar Fuentes
2020-12-13 21:46 ` steve-humphreys
2020-12-13 22:37 ` Joost Kremers
2020-12-13 23:08 ` Joost Kremers
2020-12-13 22:43 ` Stefan Monnier
2020-12-13 23:25 ` steve-humphreys
2020-12-13 23:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 0:19 ` steve-humphreys
2020-12-14 0:37 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 2:54 ` steve-humphreys
2020-12-14 2:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 3:23 ` steve-humphreys
2020-12-14 4:07 ` Michael Heerdegen
2020-12-14 4:16 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 4:23 ` steve-humphreys
2020-12-14 4:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 5:13 ` steve-humphreys
2020-12-14 6:20 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 6:25 ` steve-humphreys
2020-12-14 5:28 ` steve-humphreys [this message]
2020-12-14 6:26 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 10:25 ` steve-humphreys
2020-12-14 5:55 ` steve-humphreys
2020-12-14 6:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-14 17:22 ` Michael Heerdegen
2020-12-14 18:25 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-15 0:17 ` steve-humphreys
2020-12-15 1:38 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-12-13 21:41 ` steve-humphreys
2020-12-13 23:31 ` Emanuel Berg 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=trinity-f82aeb5a-ee8b-478a-bd66-a2fb4cbe2fe1-1607923711448@3c-app-mailcom-bs09 \
--to=steve-humphreys@gmx.com \
--cc=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/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.