From: Philipp <p.stephani2@gmail.com>
To: Arthur Miller <arthur.miller@live.com>
Cc: Michael Heerdegen <michael_heerdegen@web.de>, emacs-devel@gnu.org
Subject: Re: Q: BLV for function slots + BL obarray/hmap for symbol lookup?
Date: Sun, 30 May 2021 14:44:57 +0200 [thread overview]
Message-ID: <2779765C-6A7D-4342-BBFE-A774125A6EC5@gmail.com> (raw)
In-Reply-To: <AM9PR09MB49776B185ED1DF5F5A75086196209@AM9PR09MB4977.eurprd09.prod.outlook.com>
> Am 30.05.2021 um 04:57 schrieb Arthur Miller <arthur.miller@live.com>:
>
> Michael Heerdegen <michael_heerdegen@web.de> writes:
>
>> Arthur Miller <arthur.miller@live.com> writes:
>>
>>
>>> (setq-local obarray (copy-sequence obarray))
>> ^^^^^^^^^^^^^
>>
>> I guess this is something different than with the originally suggested
>> `obarray-copy'.
>>
>> I once was told that obarray is not just simply an array of existing
>> symbols
>
> You mean I got a shallow copy of the obarray instead of a deep copy?
I wouldn't call it a shallow copy; you get a weird object that doesn't behave as expected:
(let ((a (obarray-make 1)))
(intern "u" a)
(intern "v" a)
(let ((b (copy-sequence a)))
(unintern "u" b))
(let ((syms ()))
(mapatoms (lambda (s) (push s syms)) a)
syms))
=> (v)
Here, uninterning "u" from the "copy" has also removed it from the original.
>
> Where do I find this obarray-copy? :-) I don't see it in 27.1.
It doesn't exist yet, you'll need to write it. For example:
(defun obarray-copy (ob)
(let ((r (obarray-make (obarray-size ob))))
(obarray-map (lambda (sym) (obarray-put (symbol-name sym) r))) ob)
r))
>
>> (length obarray) ==> 15121
>
> Yes, I get the same apocalytpic number, surprise :).
>
>> (let ((i 0)) (mapatoms (lambda (_) (cl-incf i))) i) ==> 66002
>
> I get 45416.
>
> This is beyond my knowledge about how obarrays in Emacs are made.
See the node "Creating Symbols" in the ELisp manual, which explains the details. (Probably too well, since they are really implementation details.)
For the full picture, check the definition of 'struct Lisp_Symbol' in lisp.h and the obarray functions in lread.c.
Obarrays are rather weird objects that are not really well supported by most Elisp functions. You can only work with them reliably using the dedicated obarray functions (intern, unintern, mapatoms, the functions from obarray.el).
next prev parent reply other threads:[~2021-05-30 12:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-22 21:46 Q: BLV for function slots + BL obarray/hmap for symbol lookup? Arthur Miller
2021-05-22 22:30 ` Stefan Monnier
2021-05-22 23:31 ` Arthur Miller
2021-05-23 3:25 ` Stefan Monnier
2021-05-23 9:00 ` Arthur Miller
2021-05-23 15:27 ` Stefan Monnier
2021-05-23 16:23 ` Arthur Miller
2021-05-29 7:31 ` Arthur Miller
2021-05-29 12:44 ` Michael Heerdegen
2021-05-30 2:57 ` Arthur Miller
2021-05-30 12:44 ` Philipp [this message]
2021-05-29 13:47 ` Stefan Monnier
2021-05-30 2:30 ` Arthur Miller
2021-05-30 2:44 ` Stefan Monnier
2021-05-30 12:17 ` Arthur Miller
2021-05-29 13:56 ` Stefan Monnier
2021-05-23 18:22 ` Clément Pit-Claudel
2021-05-23 20:23 ` Arthur Miller
2021-05-23 21:41 ` Clément Pit-Claudel
2021-05-24 12:37 ` Arthur Miller
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2779765C-6A7D-4342-BBFE-A774125A6EC5@gmail.com \
--to=p.stephani2@gmail.com \
--cc=arthur.miller@live.com \
--cc=emacs-devel@gnu.org \
--cc=michael_heerdegen@web.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).