Document reserved keys
[emacs.git] / lisp / obarray.el
blob90a796591870558d23e5afb2f617e8835a36ae6c
1 ;;; obarray.el --- obarray functions -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015-2018 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: obarray functions
7 ;; Package: emacs
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This file provides function for working with obarrays.
28 ;;; Code:
30 (defconst obarray-default-size 59
31 "The value 59 is an arbitrary prime number that gives a good hash.")
33 (defun obarray-make (&optional size)
34 "Return a new obarray of size SIZE or `obarray-default-size'."
35 (let ((size (or size obarray-default-size)))
36 (if (< 0 size)
37 (make-vector size 0)
38 (signal 'wrong-type-argument '(size 0)))))
40 (defun obarray-size (ob)
41 "Return the number of slots of obarray OB."
42 (length ob))
44 (defun obarrayp (object)
45 "Return t if OBJECT is an obarray."
46 (and (vectorp object)
47 (< 0 (length object))))
49 ;; Don’t use obarray as a variable name to avoid shadowing.
50 (defun obarray-get (ob name)
51 "Return symbol named NAME if it is contained in obarray OB.
52 Return nil otherwise."
53 (intern-soft name ob))
55 (defun obarray-put (ob name)
56 "Return symbol named NAME from obarray OB.
57 Creates and adds the symbol if doesn't exist."
58 (intern name ob))
60 (defun obarray-remove (ob name)
61 "Remove symbol named NAME if it is contained in obarray OB.
62 Return t on success, nil otherwise."
63 (unintern name ob))
65 (defun obarray-map (fn ob)
66 "Call function FN on every symbol in obarray OB and return nil."
67 (mapatoms fn ob))
69 (provide 'obarray)
70 ;;; obarray.el ends here