I know, consp is a primitive,
but not in AutoLISP and I want to find the best implementation
within lisp:
1) (defun consp (x) (and x (listp x)))
2) (defun consp (x) (not (atom x)))
Are both of them valid in CL too? (In AutoLISP they are valid)
Which is the best? (thinking of an xlisp implementation behind)
My guess is that the macro (and) should be somewhat
slower than (not (atom x))
Thanks
-- Reini Urban
AutoCAD stuff at http://xarch.tu-graz.ac.at/autocad/
In article <··················@judy>,
Reini Urban <······@sbox.tu-graz.ac.at> wrote:
>1) (defun consp (x) (and x (listp x)))
>2) (defun consp (x) (not (atom x)))
>
>Are both of them valid in CL too? (In AutoLISP they are valid)
Yes. The first one is kind of ironic, since LISTP is probably implemented
in most CLs as:
(defun listp (x) (or (consp x) (null x)))
>Which is the best? (thinking of an xlisp implementation behind)
>
>My guess is that the macro (and) should be somewhat
>slower than (not (atom x))
I would guess so, since it's just a single type comparison. Interally,
LISTP needs to be implemented something like what I wrote above.
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
Reini Urban <······@sbox.tu-graz.ac.at> writes:
> 1) (defun consp (x) (and x (listp x)))
> 2) (defun consp (x) (not (atom x)))
>
> Are both of them valid in CL too? (In AutoLISP they are valid)
> Which is the best? (thinking of an xlisp implementation behind)
Well the problem is that (not (atom x)) will be true for a
vector, which is certainly not a cons.
In article <·············@davidf_nt.mks.com> ······@mks.com (David J. Fiander) writes:
Reini Urban <······@sbox.tu-graz.ac.at> writes:
> 1) (defun consp (x) (and x (listp x)))
> 2) (defun consp (x) (not (atom x)))
>
> Are both of them valid in CL too? (In AutoLISP they are valid)
> Which is the best? (thinking of an xlisp implementation behind)
Well the problem is that (not (atom x)) will be true for a
vector, which is certainly not a cons.
From CLtL2:
----------------------------------------
[Function]
atom object
The predicate atom is true if its argument is not a cons, and otherwise is
false. Note that (atom '()) is true, because () <-> nil.
(atom x) == (typep x 'atom) == (not (typep x 'cons))
----------------------------------------
Sunil
In article <···············@northside.cc.gatech.edu>,
Sunil Mishra <·······@northside.cc.gatech.edu> wrote:
>
> Well the problem is that (not (atom x)) will be true for a
> vector, which is certainly not a cons.
Eh???
? (atom #( 1 2 3 ))
T
>
>The predicate atom is true if its argument is not a cons,
if "not a cons" produces true or in otherwords when a cons produce NIL.
Then negating that should produce T only when a cons.
>(atom x) == (typep x 'atom) == (not (typep x 'cons))
(not (not (typep x 'cons ))) == (typep x 'cons )
--
Lyman S. Taylor "Because no matter where you go,
(·····@cc.gatech.edu) there you are."
Buckaroo Banzai
·····@cc.gatech.edu (Lyman S. Taylor) writes:
A second refutation of my off the cuff remark.
"I, David J. Fiander, reaffirm my vow to treat Usenet as a
read-only medium except in those newsgroups where I clearly know
as much as the experts that I recognize therein (which to be
honest is none)."
- David