From: Gerd Moellmann Date: Thu, 4 Oct 2001 10:10:35 +0000 (+0000) Subject: (LIST_END_P, FOREACH): New macros. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e08f3345342bc885672bdee7bb0bceb06efa138b;p=emacs.git (LIST_END_P, FOREACH): New macros. --- diff --git a/src/lisp.h b/src/lisp.h index aa9816e8f2f..e7de504f464 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3060,3 +3060,31 @@ extern Lisp_Object Vdirectory_sep_char; #else #define SWITCH_ENUM_CAST(x) (x) #endif + +/* Loop over Lisp list LIST. Signal an error if LIST is not a proper + list, or if it contains circles. + + HARE and TORTOISE should be the names of Lisp_Object variables, and + N should be the name of an EMACS_INT variable declared in the + function where the macro is used. Each nested loop should use + its own variables. + + In the loop body, HARE is set to each cons of LIST, and N is the + length of the list processed so far. */ + +#define LIST_END_P(list, obj) \ + (NILP (obj) \ + ? 1 \ + : (CONSP (obj) \ + ? 0 \ + : (wrong_type_argument (Qlistp, (list), 0)), 1)) + +#define FOREACH(hare, list, tortoise, n) \ + for (tortoise = hare = (list), n = 0; \ + !LIST_END_P (list, hare); \ + (hare = XCDR (hare), ++n, \ + ((n & 1) != 0 \ + ? (tortoise = XCDR (tortoise), \ + (EQ (hare, tortoise) \ + && (circular_list_error ((list)), 1))) \ + : 0)))