From: Heime <heimeborgia@protonmail.com>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: tomas@tuxteam.de, help-gnu-emacs@gnu.org
Subject: Re: Easy to add with push but not to the end of a list
Date: Tue, 29 Nov 2022 10:15:35 +0000 [thread overview]
Message-ID: <1U5D5raKm6LALc-O6Arn0DkwBYTxGl03zPs0Ypi6V55fdnDFGmizuGVG5yG8D3uyvVsbPYb1APAU9adrRwINbJOizxpoVvHr3GQFnWzs0Ek=@protonmail.com> (raw)
In-Reply-To: <87wn7ew474.fsf@mbork.pl>
------- Original Message -------
On Tuesday, November 29th, 2022 at 8:33 AM, Marcin Borkowski <mbork@mbork.pl> wrote:
> On 2022-11-29, at 08:56, Heime heimeborgia@protonmail.com wrote:
>
> > Programming has got nothing to do with engineering or craft.
>
>
> What is it, then? (I'm genuinely curious about your opinion.)
Programming should be included in the Department of Sports. :)
> > > Singly linked lists are a tool. They are simple, lightweight,
> > > and appropriate for keeping things in sequence, and for adding
> > > things at the front. Not at the end.
> >
> > Stefan mentioned using reverse to put it into another list. If needed
> > the execution time would not be much different than actually place
> > new elements at end of list.
>
>
> The difference is that you keep adding items at the front and then
> reverse the list /once/.
>
> Another pattern you might use is to ditch lists and keep the items in
> a temporary buffer, keeping point at its end (which is easy with
> `insert'), and then traverse the buffer to gather the results as needed. You might even want to keep them in a buffer as a printed representation of a list, and then read it, using the Elisp parser. (I don't know what function would help with that, but I'm pretty certain such a function exists.) Not sure how efficient this would be, but I'd guess it could be pretty good with really large number of items. Yet another option would be to keep the whole list in some variable, but use another variable (say,` last') as a "pointer" to the last cons of
> that list. Then, you can define `fast-append' like this: (defvar last nil) (defvar my-list nil) (defun fast-append (el) "Append EL at the end of` my-list' in O(1) time."
> (if (not my-list)
> (setf my-list (cons el nil)
> last my-list)
> (setf (cdr last) (cons el nil)
> last (cdr last))))
>
> This then would be O(1).
>
> > > Core library functions express idioms. They are expected to
> > > help people to find patterns on how to use tools appropriately
> > > (it's not much different from tools: a screwdriver has a
> > > handle, which spells "grip me here, please").
> > >
> > > Adding a function to core (say `hsup') which suggests that
> > > it is as easy to push something at the end of a list would
> > > be misleading people to hold the screwdriver (or the knife!)
> > > at the wrong end and hurt themselves.
> >
> > Nobody will get hurt. Just inefficient for long lists or for
> > large number of calls.
>
> Every time someone appends to the end of a singly linked list, a cute
> kitty dies...
>
> ;-)
Pussy Riot it is, then!
> --
> Marcin Borkowski
> http://mbork.pl
next prev parent reply other threads:[~2022-11-29 10:15 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 2:26 Easy to add with push but not to the end of a list Heime
2022-11-28 2:43 ` [External] : " Drew Adams
2022-11-28 3:45 ` Heime
2022-11-28 6:11 ` Drew Adams
2022-11-28 20:00 ` Emanuel Berg
2022-11-28 5:18 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-11-28 20:19 ` Emanuel Berg
2022-11-28 21:56 ` [External] : " Drew Adams
2022-11-28 22:45 ` Emanuel Berg
2022-11-28 22:01 ` Heime
2022-11-28 22:24 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-11-28 22:58 ` Emanuel Berg
2022-11-30 14:10 ` tomas
2022-11-30 16:12 ` Emanuel Berg
2022-11-28 22:46 ` Emanuel Berg
2022-11-28 22:50 ` Emanuel Berg
2022-11-29 5:23 ` tomas
2022-11-29 5:32 ` Emanuel Berg
2022-11-29 7:56 ` Heime
2022-11-29 8:33 ` Marcin Borkowski
2022-11-29 10:00 ` Emanuel Berg
2022-11-29 10:05 ` Emanuel Berg
2022-11-29 10:15 ` Heime [this message]
2022-11-29 8:38 ` tomas
2022-11-29 9:54 ` Emanuel Berg
2022-11-29 8:17 ` Marcin Borkowski
2022-11-29 8:44 ` tomas
2022-11-29 12:08 ` Dr Rainer Woitok
2022-11-29 19:54 ` Of cars and mice [was: Easy to add with push but not to the end of a list] tomas
2022-11-30 1:17 ` Emanuel Berg
2022-11-30 1:13 ` Easy to add with push but not to the end of a list Emanuel Berg
2022-11-28 19:59 ` Emanuel Berg
2022-11-28 21:56 ` [External] : " Drew Adams
2022-11-28 22:18 ` Heime
2022-11-28 22:41 ` Drew Adams
2022-11-29 11:17 ` Dr Rainer Woitok
2022-11-30 17:10 ` Michael Heerdegen
2022-11-30 18:17 ` [External] : " Drew Adams
2022-11-30 19:30 ` Emanuel Berg
2022-12-01 15:11 ` Michael Heerdegen
2022-12-01 17:25 ` Emanuel Berg
2022-12-03 21:29 ` Michael Heerdegen
2022-12-05 23:35 ` Emanuel Berg
2022-12-06 1:36 ` Michael Heerdegen
2022-12-06 1:43 ` Emanuel Berg
2022-12-06 2:17 ` Michael Heerdegen
2022-12-06 2:40 ` Emanuel Berg
2022-12-06 13:56 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-12-06 14:45 ` Michael Heerdegen
2022-12-06 2:52 ` Emanuel Berg
2022-12-06 17:22 ` Michael Heerdegen
2022-12-06 22:30 ` Emanuel Berg
2022-12-08 23:15 ` Michael Heerdegen
2022-12-28 23:52 ` Emanuel Berg
2022-12-31 16:57 ` Michael Heerdegen
2022-12-31 22:09 ` Emanuel Berg
2023-01-01 12:16 ` Michael Heerdegen
2023-01-08 4:40 ` Emanuel Berg
2023-01-09 6:32 ` Emanuel Berg
2023-01-14 12:05 ` Michael Heerdegen
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='1U5D5raKm6LALc-O6Arn0DkwBYTxGl03zPs0Ypi6V55fdnDFGmizuGVG5yG8D3uyvVsbPYb1APAU9adrRwINbJOizxpoVvHr3GQFnWzs0Ek=@protonmail.com' \
--to=heimeborgia@protonmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=mbork@mbork.pl \
--cc=tomas@tuxteam.de \
/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.