Function: unintern
unintern is a function defined in lread.c.
Signature
(unintern NAME OBARRAY)
Documentation
Delete the symbol named NAME, if any, from OBARRAY.
The value is t if a symbol was found and deleted, nil otherwise.
NAME may be a string or a symbol. If it is a symbol, that symbol
is deleted, if it belongs to OBARRAY--no other symbol is deleted.
OBARRAY, if nil, defaults to the value of the variable obarray.
Other relevant functions are documented in the symbol group.
Probably introduced at or before Emacs version 19.29.
Shortdoc
;; symbol
(unintern "abc" my-obarray)
e.g. => t
Source Code
// Defined in /usr/src/emacs/src/lread.c
{
if (NILP (obarray)) obarray = Vobarray;
obarray = check_obarray (obarray);
Lisp_Object sym;
if (SYMBOLP (name))
sym = BARE_SYMBOL_P (name) ? name : XSYMBOL_WITH_POS (name)->sym;
else
{
CHECK_STRING (name);
char *longhand = NULL;
ptrdiff_t longhand_chars = 0;
ptrdiff_t longhand_bytes = 0;
sym = oblookup_considering_shorthand (obarray, SSDATA (name),
SCHARS (name), SBYTES (name),
&longhand, &longhand_chars,
&longhand_bytes);
xfree(longhand);
if (FIXNUMP (sym))
return Qnil;
}
/* There are plenty of symbols which will screw up the Emacs
session if we unintern them, as well as even more ways to use
`setq' or `fset' or whatnot to make the Emacs session
unusable. We don't try to prevent such mistakes here. */
struct Lisp_Obarray *o = XOBARRAY (obarray);
Lisp_Object symname = SYMBOL_NAME (sym);
ptrdiff_t idx = obarray_index (o, SSDATA (symname), SBYTES (symname));
Lisp_Object *loc = &o->buckets[idx];
if (BASE_EQ (*loc, make_fixnum (0)))
return Qnil;
struct Lisp_Symbol *s = XBARE_SYMBOL (sym);
struct Lisp_Symbol *prev = XBARE_SYMBOL (*loc);
if (prev == s)
*loc = s->u.s.next ? make_lisp_symbol (s->u.s.next) : make_fixnum (0);
else
{
do
{
struct Lisp_Symbol *next = prev->u.s.next;
if (next == s)
{
prev->u.s.next = next->u.s.next;
goto removed;
}
prev = next;
}
while (prev);
return Qnil;
}
removed:
s->u.s.interned = SYMBOL_UNINTERNED;
o->count--;
return Qt;
}