]> code.delx.au - gnu-emacs/blob - lisp/obarray.el
Rename obarray-p to obarrayp
[gnu-emacs] / lisp / obarray.el
1 ;;; obarray.el --- obarray functions -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: obarray functions
7 ;; Package: emacs
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24 ;;; Commentary:
25
26 ;; This file provides function for working with obarrays.
27
28 ;;; Code:
29
30 (defconst obarray-default-size 59
31 "The value 59 is an arbitrary prime number that gives a good hash.")
32
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)))))
39
40 (defun obarrayp (object)
41 "Return t if OBJECT is an obarray."
42 (and (vectorp object)
43 (< 0 (length object))))
44
45 (defun obarray-get (obarray name)
46 "Return symbol named NAME if it is contained in OBARRAY.
47 Return nil otherwise."
48 (intern-soft name obarray))
49
50 (defun obarray-put (obarray name)
51 "Return symbol named NAME from OBARRAY.
52 Creates and adds the symbol if doesn't exist."
53 (intern name obarray))
54
55 (defun obarray-remove (obarray name)
56 "Remove symbol named NAME if it is contained in OBARRAY.
57 Return t on success, nil otherwise."
58 (unintern name obarray))
59
60 (defun obarray-map (fn obarray)
61 "Call function FN on every symbol in OBARRAY and return nil."
62 (mapatoms fn obarray))
63
64 (provide 'obarray)
65 ;;; obarray.el ends here