diff options
| author | Richard M. Stallman | 1995-07-01 22:27:40 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-07-01 22:27:40 +0000 |
| commit | 5a30fab88d2d5e5c38517b57e7646c77d2fc29d9 (patch) | |
| tree | cb35a1bbf76d7bd89a13915d800c15ce297b2bc4 /src | |
| parent | c1c74b432075dd686aa6351440ea23bc0e0c525e (diff) | |
| download | emacs-5a30fab88d2d5e5c38517b57e7646c77d2fc29d9.tar.gz emacs-5a30fab88d2d5e5c38517b57e7646c77d2fc29d9.zip | |
(Fsafe_length): New function.
(syms_of_fns): defsubr it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 33 |
1 files changed, 33 insertions, 0 deletions
| @@ -128,6 +128,38 @@ A byte-code function object is also allowed.") | |||
| 128 | return val; | 128 | return val; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | /* This does not check for quits. That is safe | ||
| 132 | since it must terminate. */ | ||
| 133 | |||
| 134 | DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0, | ||
| 135 | "Return the length of a list, but avoid error or infinite loop.\n\ | ||
| 136 | This function never gets an error. If LIST is not really a list,\n\ | ||
| 137 | it returns 0. If LIST is circular, it returns a finite value\n\ | ||
| 138 | which is at least the number of distinct elements.") | ||
| 139 | (list) | ||
| 140 | Lisp_Object list; | ||
| 141 | { | ||
| 142 | Lisp_Object tail, halftail, length; | ||
| 143 | int len = 0; | ||
| 144 | |||
| 145 | /* halftail is used to detect circular lists. */ | ||
| 146 | halftail = list; | ||
| 147 | for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr) | ||
| 148 | { | ||
| 149 | if (EQ (tail, halftail) && len != 0) | ||
| 150 | { | ||
| 151 | len /= 2; | ||
| 152 | break; | ||
| 153 | } | ||
| 154 | len++; | ||
| 155 | if (len & 1 == 0) | ||
| 156 | halftail = XCONS (halftail)->cdr; | ||
| 157 | } | ||
| 158 | |||
| 159 | XSETINT (length, len); | ||
| 160 | return length; | ||
| 161 | } | ||
| 162 | |||
| 131 | DEFUN ("string-equal", Fstring_equal, Sstring_equal, 2, 2, 0, | 163 | DEFUN ("string-equal", Fstring_equal, Sstring_equal, 2, 2, 0, |
| 132 | "T if two strings have identical contents.\n\ | 164 | "T if two strings have identical contents.\n\ |
| 133 | Case is significant, but text properties are ignored.\n\ | 165 | Case is significant, but text properties are ignored.\n\ |
| @@ -1512,6 +1544,7 @@ Used by `featurep' and `require', and altered by `provide'."); | |||
| 1512 | defsubr (&Sidentity); | 1544 | defsubr (&Sidentity); |
| 1513 | defsubr (&Srandom); | 1545 | defsubr (&Srandom); |
| 1514 | defsubr (&Slength); | 1546 | defsubr (&Slength); |
| 1547 | defsubr (&Ssafe_length); | ||
| 1515 | defsubr (&Sstring_equal); | 1548 | defsubr (&Sstring_equal); |
| 1516 | defsubr (&Sstring_lessp); | 1549 | defsubr (&Sstring_lessp); |
| 1517 | defsubr (&Sappend); | 1550 | defsubr (&Sappend); |