[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: To be a list or not
From: |
Tom Tromey |
Subject: |
Re: To be a list or not |
Date: |
Mon, 31 Dec 2007 09:38:44 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (gnu/linux) |
>>>>> "Andreas" == Andreas Schwab <address@hidden> writes:
Andreas> Tom Tromey <address@hidden> writes:
Andreas> + return tail == Qnil ? Qt : Qnil;
Andreas> NILP (tail)
Thanks, I didn't know about that. BTW I see a number of EQ(...,Qnil)
comparisons in the current code.
Here's a revised patch.
I considered Stephen's suggestion of having two loops, but I think it
probably is not worthwhile.
Tom
2007-12-31 Tom Tromey <address@hidden>
* lisp.h (Ftrue_list_p): Declare.
* data.c (Ftrue_list_p): New function.
(syms_of_data): Update.
Index: data.c
===================================================================
RCS file: /sources/emacs/emacs/src/data.c,v
retrieving revision 1.287
diff -u -r1.287 data.c
--- data.c 22 Nov 2007 20:29:48 -0000 1.287
+++ data.c 31 Dec 2007 17:04:24 -0000
@@ -285,6 +285,28 @@
return Qnil;
return Qt;
}
+
+DEFUN ("true-list-p", Ftrue_list_p, Strue_list_p, 1, 1, 0,
+ doc: /* Return t if OBJECT is an acyclic, nil-terminated list. */)
+ (object)
+ Lisp_Object object;
+{
+ Lisp_Object tail, halftail;
+ int len = 0;
+
+ /* halftail is used to detect circular lists. */
+ halftail = object;
+ for (tail = object; CONSP (tail); tail = XCDR (tail))
+ {
+ if (EQ (tail, halftail) && len != 0)
+ return Qnil;
+ ++len;
+ if ((len & 1) == 0)
+ halftail = XCDR (halftail);
+ }
+
+ return NILP (tail) ? Qt : Qnil;
+}
DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
doc: /* Return t if OBJECT is a symbol. */)
@@ -3291,6 +3313,7 @@
defsubr (&Stype_of);
defsubr (&Slistp);
defsubr (&Snlistp);
+ defsubr (&Strue_list_p);
defsubr (&Sconsp);
defsubr (&Satom);
defsubr (&Sintegerp);
Index: lisp.h
===================================================================
RCS file: /sources/emacs/emacs/src/lisp.h,v
retrieving revision 1.603
diff -u -r1.603 lisp.h
--- lisp.h 22 Nov 2007 01:01:26 -0000 1.603
+++ lisp.h 31 Dec 2007 17:05:52 -0000
@@ -2205,6 +2208,7 @@
EXFUN (Fconsp, 1);
EXFUN (Fatom, 1);
EXFUN (Fnlistp, 1);
+EXFUN (Ftrue_list_p, 1);
EXFUN (Fintegerp, 1);
EXFUN (Fnatnump, 1);
EXFUN (Fsymbolp, 1);
- To be a list or not, Lennart Borgman (gmail), 2007/12/28
- Re: To be a list or not, Nick Roberts, 2007/12/28
- Re: To be a list or not, Lennart Borgman (gmail), 2007/12/28
- Re: To be a list or not, Nick Roberts, 2007/12/28
- Re: To be a list or not, Lennart Borgman (gmail), 2007/12/28
- Re: To be a list or not, Bob Rogers, 2007/12/28
- Re: To be a list or not, Stephen J. Turnbull, 2007/12/29
- Re: To be a list or not, Miles Bader, 2007/12/29
- Re: To be a list or not, Tom Tromey, 2007/12/29
- Re: To be a list or not, Andreas Schwab, 2007/12/29
- Re: To be a list or not,
Tom Tromey <=
- Re: To be a list or not, Andreas Schwab, 2007/12/31
- Re: To be a list or not, Stephen J. Turnbull, 2007/12/29
- Re: To be a list or not, Bob Rogers, 2007/12/29
- Re: To be a list or not, Richard Stallman, 2007/12/29
- Re: To be a list or not, Richard Stallman, 2007/12/29
Re: To be a list or not, Eric Hanchrow, 2007/12/28
Re: To be a list or not, Richard Stallman, 2007/12/29