Mercurial > hg > xemacs-beta
comparison src/fns.c @ 5299:28651c24b3f8
Error in #'list-length if LIST is dotted; check for this error with #'mapcar
src/ChangeLog addition:
2010-11-06 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (Flist_length): Error if LIST is dotted in this function;
document this behaviour.
tests/ChangeLog addition:
2010-11-06 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el (malformed-list): Check that #'mapcar,
#'map and #'list-length throw this error when appropriate.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 06 Nov 2010 14:51:13 +0000 |
parents | 99de5fd48e87 |
children | 9f738305f80f |
comparison
equal
deleted
inserted
replaced
5298:99006e0b3a84 | 5299:28651c24b3f8 |
---|---|
343 for shortest_length_among_sequences(), below, for the various sequence | 343 for shortest_length_among_sequences(), below, for the various sequence |
344 functions that can usefully operate on circular lists. */ | 344 functions that can usefully operate on circular lists. */ |
345 | 345 |
346 DEFUN ("list-length", Flist_length, 1, 1, 0, /* | 346 DEFUN ("list-length", Flist_length, 1, 1, 0, /* |
347 Return the length of LIST. Return nil if LIST is circular. | 347 Return the length of LIST. Return nil if LIST is circular. |
348 Error if LIST is dotted. | |
348 */ | 349 */ |
349 (list)) | 350 (list)) |
350 { | 351 { |
351 Lisp_Object hare, tortoise; | 352 Lisp_Object hare, tortoise; |
352 Elemcount len; | 353 Elemcount len; |
355 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); | 356 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); |
356 hare = XCDR (hare), len++) | 357 hare = XCDR (hare), len++) |
357 { | 358 { |
358 if (len & 1) | 359 if (len & 1) |
359 tortoise = XCDR (tortoise); | 360 tortoise = XCDR (tortoise); |
361 } | |
362 | |
363 if (!LISTP (hare)) | |
364 { | |
365 signal_malformed_list_error (list); | |
360 } | 366 } |
361 | 367 |
362 return EQ (hare, tortoise) && len != 0 ? Qnil : make_int (len); | 368 return EQ (hare, tortoise) && len != 0 ? Qnil : make_int (len); |
363 } | 369 } |
364 | 370 |