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

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

RE: [External] : Re: Any faster way to find frequency of words?


From: Drew Adams
Subject: RE: [External] : Re: Any faster way to find frequency of words?
Date: Mon, 10 May 2021 16:34:53 +0000

> >   (let ((al  ()))
> >     (maphash (lambda (key val) (push (cons key val) al))
> >              hash-table)
> >     (nreverse al)))
> 
> That may be better, nicer.
> 
> I wonder if nreverse is really needed as function just returns some
> data, is that data anyway destroyed thereafter?

It creates new list structure, for local var `al'.
So there's no problem with destructively modifying
that list structure - nothing else can be using it
in this context.

> I just wonder if the order matters. It should not matter in hash,
> alist, plist I guess.

Order can matter in an alist or plist.

"Can", because certainly some code can use such a
list without caring about the order.

Alists, in particular, are expressly designed to
allow for multiple elements with the same key.
For most purposes, only the first element with
the same key is accessed; it "shadows" subsequent
elements in the list.  There are various advantages
to being able to have multiple entries.

reply via email to

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