From: rich
Subject: car v/s first
Date: 
Message-ID: <1141115773.947863.192880@p10g2000cwp.googlegroups.com>
Hello all,
 I am using the following code for some checking as ;

(defun validator (pat lst pattern-lst)

 (cond
       ((null pattern-lst) T)

       ((AND(Equal (first pat) (first (first pattern-lst)))
                     (Equal (first lst)(second (first pattern-lst))))
T )

       ((Equal (first pat) (first (first pattern-lst))) nil)

       (T(validator pat lst (cdr pattern-lst)))))

and the values for various parameters are

pat=(?x)
lst=(b)
patter-lst= (?x b)

now when i use the car and cdr functions in place of first and second
fucntions which i hve used in the code it gives me nil otherwise its
works fine findin the duplicates..if present.

Why is that so? are the car and first behave differently at times.. or
i am missing smthin ...

thanks

From: Kaz Kylheku
Subject: Re: car v/s first
Date: 
Message-ID: <1141145335.969279.122460@j33g2000cwa.googlegroups.com>
rich wrote:
> now when i use the car and cdr functions in place of first and second

CAR and CDR correspond to FIRST and REST, not to FIRST and SECOND.
From: Pascal Costanza
Subject: Re: car v/s first
Date: 
Message-ID: <46igm5Fas14oU2@individual.net>
rich wrote:
> Hello all,
>  I am using the following code for some checking as ;
> 
> (defun validator (pat lst pattern-lst)
> 
>  (cond
>        ((null pattern-lst) T)
> 
>        ((AND(Equal (first pat) (first (first pattern-lst)))
>                      (Equal (first lst)(second (first pattern-lst))))
> T )
> 
>        ((Equal (first pat) (first (first pattern-lst))) nil)
> 
>        (T(validator pat lst (cdr pattern-lst)))))
> 
> and the values for various parameters are
> 
> pat=(?x)
> lst=(b)
> patter-lst= (?x b)
> 
> now when i use the car and cdr functions in place of first and second
> fucntions which i hve used in the code it gives me nil otherwise its
> works fine findin the duplicates..if present.
> 
> Why is that so? are the car and first behave differently at times.. or
> i am missing smthin ...

car and cdr behave like first and rest. If you want to express second, 
that's cadr.


Pascal

-- 
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
From: Simon Brooke
Subject: Re: car v/s first
Date: 
Message-ID: <u7egd3-uik.ln1@gododdin.internal.jasmine.org.uk>
in message <························@p10g2000cwp.googlegroups.com>, rich
(··········@yahoo.co.in') wrote:

> Hello all,
>  I am using the following code for some checking as ;
> 
> (defun validator (pat lst pattern-lst)
> 
>  (cond
>        ((null pattern-lst) T)
> 
>        ((AND(Equal (first pat) (first (first pattern-lst)))
>                      (Equal (first lst)(second (first pattern-lst))))
> T )
> 
>        ((Equal (first pat) (first (first pattern-lst))) nil)
> 
>        (T(validator pat lst (cdr pattern-lst)))))
> 
> and the values for various parameters are
> 
> pat=(?x)
> lst=(b)
> patter-lst= (?x b)
> 
> now when i use the car and cdr functions in place of first and second
> fucntions which i hve used in the code it gives me nil otherwise its
> works fine findin the duplicates..if present.
> 
> Why is that so? are the car and first behave differently at times.. or
> i am missing smthin ...

cdr isn't second, it's rest.
cadr is second.

-- 
·····@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
    .::;===r==\   
   /  /___||___\____         
  //==\-  ||-  |  /__\(  MS Windows IS an operating environment.
 //____\__||___|_//  \|: C++ IS an object oriented programming language. 
   \__/ ~~~~~~~~~ \__/   Citroen 2cv6 IS a four door family saloon.