From:            St�ph.
Subject: basic LISP problem
Date: 
Message-ID: <a2h3q2$cts$1@esprit.ciril.fr>
Hello, I can't understand what this function is doing and how
its first line works. Can anybody explain me this ?

Tanks.

St�ph.
---
(defun  find-all  (item  sequence  &rest  keyword-args &key
(test  #'eql)  test-not  &allow-other-keys)
  (if  test-not
        (apply  #'remove  item  sequence
                :test-not  (complement  test-not)  keyword-args)
        (apply  #'remove  item  sequence
                :test  (complement  test)  keyword-args)))

From: Will Deakin
Subject: Re: basic LISP problem
Date: 
Message-ID: <3C4C1AB6.3090709@hotmail.com>
  St�ph. wrote:

> Can anybody explain me this ?

Hmmm. I *hope* this isn't an homework assignment. Anyway, break 
this down into bits like:

 > (defun  find-all  (item  sequence  &rest  keyword-args &key

> (test  #'eql)  test-not  &allow-other-keys)

This is the function declaration. This insists that you pass the 
function an item and a sequence and allows the the possibility of 
passing a list of arguments which is then used later or some 
keywords. Such as:
 > (defun eeyore (bernard &rest cribbens)
     (format t "~S is mandatory~%whilst ~S is not~%"
  	bernard cribbens))
 > (eeyore "poo" "tigger")
"poo" is mandatory
whilst ("tigger") is not
NIL

Then you have:
 > (defun owl (&key (bernard "rabbit") &allow-other-keys)
     (format t "~S is optional~%" bernard))
 > (owl)
"rabbit" is optional
NIL
 > (owl :bernard "poo")
"poo" is optional
NIL
The (bernard "rabbit") set the default value otherwise the 
default is nil.

This is all fairly straightforward. The &allow-other-keys in the 
definition of piglet then gives you the opportunity to do have 
extra key values without having an error reported:
 > (defun piglet (&key (bernard 'cribbens) &allow-other-keys)
     (format t "~S is optional~%" bernard))
 > (piglet :bresslaw "tigger")

"cribbens" is optional
NIL

>   (if  test-not
>         (apply  #'remove  item  sequence
>                 :test-not  (complement  test-not)  keyword-args)
>         (apply  #'remove  item  sequence
>                 :test  (complement  test)  keyword-args)))
This then runs:

(apply #'remove item sequence
        :test-not  (complement  test-not)  keyword-args)
if there is a value of test-not and:
(apply #'remove item sequence
        :test-not  (complement test-not) keyword-args)
if there isn't.

:)w
From: Kenny Tilton
Subject: Re: basic LISP problem
Date: 
Message-ID: <3C4C1FF2.FC6BCBF4@nyc.rr.com>
" St�ph." wrote:
> 
> Hello, I can't understand what this function is doing and how
> its first line works. Can anybody explain me this ?
> 
> Tanks.
> 
> St�ph.
> ---
> (defun  find-all  (item  sequence  &rest  keyword-args &key
> (test  #'eql)  test-not  &allow-other-keys)
>   (if  test-not
>         (apply  #'remove  item  sequence
>                 :test-not  (complement  test-not)  keyword-args)
>         (apply  #'remove  item  sequence
>                 :test  (complement  test)  keyword-args)))

Not sure what you mean by "first line", what with line wrap I see in my
newsreader. If you meant all of (regardless of wrap):

 (defun find-all (item sequence &rest keyword-args &key (test #'eql)
test-not &allow-other-keys)...

...there is a lot to explain. you might want to read up on keyword and
optional args to functions. &allow-other-keys lets the caller of
find-all pass thru other keyword args to remove, for one.

If you meant just the part that I saw wrapped:

  (test  #'eql)  test-not  &allow-other-keys)

that is not a "line of code" as in C, that is just a continuation of the
function signature (defun find-all........).

kenny
clinisys