Merge branch 'master' into comment-cache
[emacs.git] / lisp / obarray.el
blobaaffe00a07237688b53ef51e21a41faea034790a
1 ;;; obarray.el --- obarray functions -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015-2017 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 <http://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 obarrayp (object)
41 "Return t if OBJECT is an obarray."
42 (and (vectorp object)
43 (< 0 (length object))))
45 ;; Don’t use obarray as a variable name to avoid shadowing.
46 (defun obarray-get (ob name)
47 "Return symbol named NAME if it is contained in obarray OB.
48 Return nil otherwise."
49 (intern-soft name ob))
51 (defun obarray-put (ob name)
52 "Return symbol named NAME from obarray OB.
53 Creates and adds the symbol if doesn't exist."
54 (intern name ob))
56 (defun obarray-remove (ob name)
57 "Remove symbol named NAME if it is contained in obarray OB.
58 Return t on success, nil otherwise."
59 (unintern name ob))
61 (defun obarray-map (fn ob)
62 "Call function FN on every symbol in obarray OB and return nil."
63 (mapatoms fn ob))
65 (provide 'obarray)
66 ;;; obarray.el ends here