emacs-devel
[Top][All Lists]
Advanced

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

Re: Q: BLV for function slots + BL obarray/hmap for symbol lookup?


From: Philipp
Subject: Re: Q: BLV for function slots + BL obarray/hmap for symbol lookup?
Date: Sun, 30 May 2021 14:44:57 +0200


> 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).


reply via email to

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