/* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
- Copyright (C) 1985, 1986, 1988, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1985, 1986, 1988, 1993 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "syssignal.h"
#ifdef LISP_FLOAT_TYPE
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#endif
#include <math.h>
#endif /* LISP_FLOAT_TYPE */
register Lisp_Object sym, newdef;
{
CHECK_SYMBOL (sym, 0);
+
+ if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
+ Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
+ Vautoload_queue);
+ XSYMBOL (sym)->function = newdef;
+ return newdef;
+}
+
+/* This name should be removed once it is eliminated from elsewhere. */
+
+DEFUN ("defalias", Fdefalias, Sdefalias, 2, 2, 0,
+ "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
+Associates the function with the current load file, if any.")
+ (sym, newdef)
+ register Lisp_Object sym, newdef;
+{
+ CHECK_SYMBOL (sym, 0);
+ if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
+ Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
+ Vautoload_queue);
+ XSYMBOL (sym)->function = newdef;
+ LOADHIST_ATTACH (sym);
+ return newdef;
+}
+
+DEFUN ("define-function", Fdefine_function, Sdefine_function, 2, 2, 0,
+ "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
+Associates the function with the current load file, if any.")
+ (sym, newdef)
+ register Lisp_Object sym, newdef;
+{
+ CHECK_SYMBOL (sym, 0);
if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
Vautoload_queue);
XSYMBOL (sym)->function = newdef;
+ LOADHIST_ATTACH (sym);
return newdef;
}
indirect_function (object)
register Lisp_Object object;
{
- Lisp_Object tortise, hare;
+ Lisp_Object tortoise, hare;
- hare = tortise = object;
+ hare = tortoise = object;
for (;;)
{
break;
hare = XSYMBOL (hare)->function;
- tortise = XSYMBOL (tortise)->function;
+ tortoise = XSYMBOL (tortoise)->function;
- if (EQ (hare, tortise))
+ if (EQ (hare, tortoise))
Fsignal (Qcyclic_function_indirection, Fcons (object, Qnil));
}
cons_to_long (c)
Lisp_Object c;
{
- int top, bot;
+ Lisp_Object top, bot;
if (INTEGERP (c))
return XINT (c);
top = XCONS (c)->car;
extern Lisp_Object float_arith_driver ();
Lisp_Object
-arith_driver
- (code, nargs, args)
+arith_driver (code, nargs, args)
enum arithop code;
int nargs;
register Lisp_Object *args;
case Amult: accum *= next; break;
case Adiv:
if (!argnum) accum = next;
- else accum /= next;
+ else
+ {
+ if (next == 0)
+ Fsignal (Qarith_error, Qnil);
+ accum /= next;
+ }
break;
case Alogand: accum &= next; break;
case Alogior: accum |= next; break;
if (!argnum)
accum = next;
else
- accum /= next;
+ {
+ if (next == 0)
+ Fsignal (Qarith_error, Qnil);
+ accum /= next;
+ }
break;
case Alogand:
case Alogior:
f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1);
f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2);
+ if (f2 == 0)
+ Fsignal (Qarith_error, Qnil);
+
#if defined (USG) || defined (sun) || defined (ultrix) || defined (hpux)
f1 = fmod (f1, f2);
#else
f1 = drem (f1, f2);
#endif
- if (f1 < 0)
+ /* If the "remainder" comes out with the wrong sign, fix it. */
+ if ((f1 < 0) != (f2 < 0))
f1 += f2;
return (make_float (f1));
}
CHECK_NUMBER_COERCE_MARKER (num2, 1);
#endif /* not LISP_FLOAT_TYPE */
+ if (XFASTINT (num2) == 0)
+ Fsignal (Qarith_error, Qnil);
+
XSET (val, Lisp_Int, XINT (num1) % XINT (num2));
return val;
}
defsubr (&Sboundp);
defsubr (&Sfboundp);
defsubr (&Sfset);
+ defsubr (&Sdefalias);
+ defsubr (&Sdefine_function);
defsubr (&Ssetplist);
defsubr (&Ssymbol_value);
defsubr (&Sset);