Function: fset

fset is a function defined in data.c.

Signature

(fset SYMBOL DEFINITION)

Documentation

Set SYMBOL's function definition to DEFINITION, and return DEFINITION.

If the resulting chain of function definitions would contain a loop, signal a cyclic-function-indirection error.

View in manual

Probably introduced at or before Emacs version 24.4.

Source Code

// Defined in /usr/src/emacs/src/data.c
{
  CHECK_SYMBOL (symbol);
  /* Perhaps not quite the right error signal, but seems good enough.  */
  if (NILP (symbol) && !NILP (definition))
    /* There are so many other ways to shoot oneself in the foot, I don't
       think this one little sanity check is worth its cost, but anyway.  */
    xsignal1 (Qsetting_constant, symbol);

  eassert (valid_lisp_object_p (definition));

  /* Ensure non-circularity.  */
  for (Lisp_Object s = definition; SYMBOLP (s) && !NILP (s);
       s = XSYMBOL (s)->u.s.function)
    if (EQ (s, symbol))
      xsignal1 (Qcyclic_function_indirection, symbol);

#ifdef HAVE_NATIVE_COMP
  register Lisp_Object function = XSYMBOL (symbol)->u.s.function;

  if (!NILP (Vnative_comp_enable_subr_trampolines)
      && SUBRP (function)
      && !NATIVE_COMP_FUNCTIONP (function)
      && !EQ (definition, Fsymbol_function (symbol)))
     calln (Qcomp_subr_trampoline_install, symbol);
#endif

  set_symbol_function (symbol, definition);

  return definition;
}