X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Fcl.el;h=8150e1d83898cb32f200b44ec27df94d6fdfc897;hb=a3c8db1e07b33da64b3af89f0c8923619e8e1ee4;hp=41a5955458ffdbc2544656e166a5965db0764f29;hpb=77dcef404dc78635f6ffa8f71a803d2bc7cc8921;p=chise%2Fxemacs-chise.git.1 diff --git a/lisp/cl.el b/lisp/cl.el index 41a5955..8150e1d 100644 --- a/lisp/cl.el +++ b/lisp/cl.el @@ -217,7 +217,7 @@ Keywords supported: :test :test-not :key" (defun cl-set-substring (str start end val) (if end (if (< end 0) (incf end (length str))) (setq end (length str))) - (if (< start 0) (incf start str)) + (if (< start 0) (incf start (length str))) (concat (and (> start 0) (substring str 0 start)) val (and (< end (length str)) (substring str end)))) @@ -269,7 +269,7 @@ If FORM is not a macro call, it is returned unchanged. Otherwise, the macro is expanded and the expansion is considered in place of FORM. When a non-macro-call results, it is returned. -The second optional arg ENVIRONMENT species an environment of macro +The second optional arg ENVIRONMENT specifies an environment of macro definitions to shadow the loaded ones for use in file byte-compilation." (let ((cl-macro-environment cl-env)) (while (progn (setq cl-macro (funcall cl-old-macroexpand cl-macro cl-env)) @@ -317,37 +317,53 @@ definitions to shadow the loaded ones for use in file byte-compilation." (defvar *gensym-counter* (* (logand (cl-random-time) 1023) 100)) +(defun gensym (&optional arg) + "Generate a new uninterned symbol. +The name is made by appending a number to a prefix. If ARG is a string, it +is the prefix, otherwise the prefix defaults to \"G\". If ARG is an integer, +the internal counter is reset to that number before creating the name. +There is no way to specify both using this function." + (let ((prefix (if (stringp arg) arg "G")) + (num (if (integerp arg) arg + (prog1 *gensym-counter* + (setq *gensym-counter* (1+ *gensym-counter*)))))) + (make-symbol (format "%s%d" prefix num)))) + +(defun gentemp (&optional arg) + "Generate a new interned symbol with a unique name. +The name is made by appending a number to ARG, default \"G\". +If ARG is not a string, it is ignored." + (let ((prefix (if (stringp arg) arg "G")) + name) + (while (intern-soft (setq name (format "%s%d" prefix *gensym-counter*))) + (setq *gensym-counter* (1+ *gensym-counter*))) + (intern name))) ;;; Numbers. -(defun floatp-safe (x) - "Return t if OBJECT is a floating point number. -On Emacs versions that lack floating-point support, this function -always returns nil." - ;;(and (numberp x) (not (integerp x))) - ;; XEmacs: use floatp. XEmacs is always compiled with - ;; floating-point, anyway. - (floatp x)) +(defun floatp-safe (object) + "Return t if OBJECT is a floating point number." + (floatp object)) -(defun plusp (x) +(defun plusp (number) "Return t if NUMBER is positive." - (> x 0)) + (> number 0)) -(defun minusp (x) +(defun minusp (number) "Return t if NUMBER is negative." - (< x 0)) + (< number 0)) -(defun oddp (x) +(defun oddp (integer) "Return t if INTEGER is odd." - (eq (logand x 1) 1)) + (eq (logand integer 1) 1)) -(defun evenp (x) +(defun evenp (integer) "Return t if INTEGER is even." - (eq (logand x 1) 0)) + (eq (logand integer 1) 0)) -(defun cl-abs (x) - "Return the absolute value of ARG." - (if (>= x 0) x (- x))) +(defun cl-abs (number) + "Return the absolute value of NUMBER." + (if (>= number 0) number (- number))) (or (fboundp 'abs) (defalias 'abs 'cl-abs)) ; This is built-in to Emacs 19 (defvar *random-state* (vector 'cl-random-state-tag -1 30 (cl-random-time))) @@ -680,9 +696,9 @@ FUNC is not added if it already appears on the list stored in HOOK." ;(load "cl-defs") ;;; Define data for indentation and edebug. -(mapc +(mapcar #'(lambda (entry) - (mapc + (mapcar #'(lambda (func) (put func 'lisp-indent-function (nth 1 entry)) (put func 'lisp-indent-hook (nth 1 entry)) @@ -733,6 +749,8 @@ FUNC is not added if it already appears on the list stored in HOOK." (defun cl-hack-byte-compiler () (if (and (not cl-hacked-flag) (fboundp 'byte-compile-file-form)) (progn + (when (not (fboundp 'cl-compile-time-init)) + (load "cl-macs" nil t)) (cl-compile-time-init) ; in cl-macs.el (setq cl-hacked-flag t))))