From: Mozis
Subject: problem with implementing member function
Date: 
Message-ID: <1158971389.939652.221790@k70g2000cwa.googlegroups.com>
Greetings,

I am newbie in the Lisp. I was trying to implement the funtionality of
member in built function.

Here si the code,

( defun mem (e l)
  (
    cond
    (
      (null l) nil
      (equal e (car l)) l
      (mem e (cdr l))
    )
  )
)

Test Code:
(mem 'a '(g a c))

Desired Ans: (a c)
Ans it gives: NIL

Let me kno if nybody get the problem.

Thanks,

Jaydeep.

From: Stefan Mandl
Subject: Re: problem with implementing member function
Date: 
Message-ID: <4njh9tFanb5hU1@news.dfncis.de>
Hi,

I re-indented your code .. do you see the problem now?

(defun mem (e l)
   (cond ((null l) nil
	 (equal e (car l)) l
	 (mem e (cdr l)))))

regards,
Stefan
From: Stefan Mandl
Subject: Re: problem with implementing member function
Date: 
Message-ID: <4njhj0Fao9r8U1@news.dfncis.de>
Ha! Forgot to use spaces instead of tabs, sorry.

(defun mem (e l)
   (cond ((null l) nil
          (equal e (car l)) l
          (mem e (cdr l)))))


PS: does anybody know what that Emacs function that converts tabs to spaces is called like?


regards,
Stefan
From: ·············@gmail.com
Subject: Re: problem with implementing member function
Date: 
Message-ID: <1158978717.751889.81900@e3g2000cwe.googlegroups.com>
Stefan Mandl wrote:
> Ha! Forgot to use spaces instead of tabs, sorry.
>
> (defun mem (e l)
>    (cond ((null l) nil
>           (equal e (car l)) l
>           (mem e (cdr l)))))
>
>
> PS: does anybody know what that Emacs function that converts tabs to spaces is called like?
> 
> 
> regards,
> Stefan

C-M-W auto-indents your code.
From: Pascal Bourguignon
Subject: Re: problem with implementing member function
Date: 
Message-ID: <87k63v49v9.fsf@thalassa.informatimago.com>
Stefan Mandl <············@informatik.uni-erlangen.de> writes:

> Ha! Forgot to use spaces instead of tabs, sorry.
>
> (defun mem (e l)
>   (cond ((null l) nil
>          (equal e (car l)) l
>          (mem e (cdr l)))))

(defun mem (e l)
  (cond ((null l) nil
                  (equal e (car l))
                  l
                  (mem e (cdr l)))))


> PS: does anybody know what that Emacs function that converts tabs to
> spaces is called like?

untabify

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"This statement is false."            In Lisp: (defun Q () (eq nil (Q)))
From: Ivan Boldyrev
Subject: Re: problem with implementing member function
Date: 
Message-ID: <tivhu3-367.ln1@ibhome.cgitftp.uiggm.nsc.ru>
On 9606 day of my life Stefan Mandl wrote:
> Ha! Forgot to use spaces instead of tabs, sorry.
>
> (defun mem (e l)
>   (cond ((null l) nil
>          (equal e (car l)) l
>          (mem e (cdr l)))))
>
> PS: does anybody know what that Emacs function that converts tabs to
> spaces is called like?

M-x untabify

But Lisp doesn't care if you use tab or space.  You code is broken in
different way.  Hint: you got wrong syntax of COND. 

-- 
Ivan Boldyrev

                                      Life!  Don't talk to me about life.
From: Javier
Subject: Re: problem with implementing member function
Date: 
Message-ID: <1159119276.502113.240400@k70g2000cwa.googlegroups.com>
Mozis ha escrito:

> Greetings,
>
> I am newbie in the Lisp. I was trying to implement the funtionality of
> member in built function.
>
> Here si the code,
>
> ( defun mem (e l)
>   (
>     cond
>     (
>       (null l) nil
>       (equal e (car l)) l
>       (mem e (cdr l))
>     )
>   )
> )

Try this:

(defun mem (e l)
  (cond
    ((null l) nil)
    ((equal e (car l)) l)
    (t (mem e (cdr l)))))

You where using cond badly. Here is its documentation:

http://www.lispworks.com/documentation/HyperSpec/Body/m_cond.htm

And in emacs, if you press TAB, it autoindents the current line,
supposing that you correctly installed SLIME. To download and install
SLIME:

http://common-lisp.net/project/slime/
From: Thomas A. Russ
Subject: Re: problem with implementing member function
Date: 
Message-ID: <ymiac4n4w1q.fsf@sevak.isi.edu>
"Mozis" <···············@gmail.com> writes:

> Greetings,
> 
> I am newbie in the Lisp. I was trying to implement the funtionality of
> member in built function.
> 
> Here si the code,
> 
> ( defun mem (e l)
>   (
>     cond
>     (
>       (null l) nil
>       (equal e (car l)) l
>       (mem e (cdr l))
>     )
>   )
> )

OK, first off, it helps the experts if you adopt a more conventional
Lisp-style of indentation and parentheses placement.  That means no
separation between "(" and the next form, and ")" don't end up on their
own lines.  This makes the code more compact and also aids in getting to
the point where the parentheses disappear when you read the code.

(defun mem (e l)
   (cond ((null l) nil
          (equal e (car l)) l
          (mem e (cdr l)))))

That said, the indentation form you have above should give you a good
clue to debugging the code.  How many COND clauses do you have?
Remember that only parentheses are significant as expression delimiters,
not end of lines.

The short answer is that you need more parentheses in your code.  In
fact, your code is equivalent to the following reformatted code, which
may make it clearer where the problem lies:

(defun mem (e l)
   (cond ((null l) nil (equal e (car l)) l (mem e (cdr l)))))

-- 
Thomas A. Russ,  USC/Information Sciences Institute