1 ;;; obarray.el --- obarray functions -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: obarray functions
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/>.
26 ;; This file provides function for working with obarrays.
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)))
38 (signal 'wrong-type-argument '(size 0)))))
40 (defun obarrayp (object)
41 "Return t if OBJECT is an obarray."
43 (< 0 (length object))))
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))
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))
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))
60 (defun obarray-map (fn obarray)
61 "Call function FN on every symbol in OBARRAY and return nil."
62 (mapatoms fn obarray))
65 ;;; obarray.el ends here