From: ············@gmail.com
Subject: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <1188821640.218751.229520@19g2000hsx.googlegroups.com>
(defun search (listy condition element)
(if (null listy) nil
(let ((c (funcall condition (car listy))))
(if c (list (car listy) element c)
(search (cdr listy) condition (+ 1 element))))))

I'm using gnu Clisp .
I get the following message :




"      (AND (= SYSTEM::OPT-NUM 0) (SYSTEM::MEMQ ':TEST
SYSTEM::KEYWORDS)
      (SYSTEM::MEMQ ':TEST-NOT SYSTEM::KEYWORDS)) must evaluate to a
non-NIL
      value.
0 errors, 0 warnings
Bye."

and it doesn't compile . Please help .

From: Karol Skocik
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <1188822382.442461.185040@y42g2000hsy.googlegroups.com>
On Sep 3, 2:14 pm, ············@gmail.com wrote:
> (defun search (listy condition element)
> (if (null listy) nil
> (let ((c (funcall condition (car listy))))
> (if c (list (car listy) element c)
> (search (cdr listy) condition (+ 1 element))))))
>
> I'm using gnu Clisp .
> I get the following message :
>
> "      (AND (= SYSTEM::OPT-NUM 0) (SYSTEM::MEMQ ':TEST
> SYSTEM::KEYWORDS)
>       (SYSTEM::MEMQ ':TEST-NOT SYSTEM::KEYWORDS)) must evaluate to a
> non-NIL
>       value.
> 0 errors, 0 warnings
> Bye."
>
> and it doesn't compile . Please help .

rename the function to something else. search is a built-in common
lisp function, and  in SBCL you get SYMBOL-PACKAGE-LOCKED-ERROR. CLISP
is maybe confused for the same reason. This compiles fine:

(defun search-1 (listy condition element)
  (if (null listy) nil
      (let ((c (funcall condition (car listy))))
        (if c
            (list (car listy) element c)
            (search-1 (cdr listy) condition (+ 1 element))))))
From: Rainer Joswig
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <joswig-A32AE8.14205003092007@news-europe.giganews.com>
In article <························@19g2000hsx.googlegroups.com>,
 ············@gmail.com wrote:

> (defun search (listy condition element)
> (if (null listy) nil
> (let ((c (funcall condition (car listy))))
> (if c (list (car listy) element c)
> (search (cdr listy) condition (+ 1 element))))))
> 
> I'm using gnu Clisp .
> I get the following message :
> 
> 
> 
> 
> "      (AND (= SYSTEM::OPT-NUM 0) (SYSTEM::MEMQ ':TEST
> SYSTEM::KEYWORDS)
>       (SYSTEM::MEMQ ':TEST-NOT SYSTEM::KEYWORDS)) must evaluate to a
> non-NIL
>       value.
> 0 errors, 0 warnings
> Bye."
> 
> and it doesn't compile . Please help .

You might want to indent your code better.

SEARCH is a built-in function in Common Lisp.
You might want to choose another name.
http://www.lispworks.com/documentation/HyperSpec/Body/f_search.htm

-- 
http://lispm.dyndns.org
From: ············@gmail.com
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <1188822774.297038.104350@22g2000hsm.googlegroups.com>
Thank you very much . It works now ! I've written far more complex
code flawlessly , and these little things still evade me . It appears
I'm still a nob . :))  .
Anyway , lisp rocks , and so does this group .
                                                      Dan .
From: Ken Tilton
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <ofYCi.36$J34.19@newsfe12.lga>
············@gmail.com wrote:
> Thank you very much . It works now ! I've written far more complex
> code flawlessly , and these little things still evade me . It appears
> I'm still a nob . :))  .

n-o-o-b, noob. <sigh>

> Anyway , lisp rocks , and so does this group .

we're getting soft. let's toast the next one properly, people.

kt

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut
From: Rainer Joswig
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <joswig-16EED8.14512703092007@news-europe.giganews.com>
In article <························@22g2000hsm.googlegroups.com>,
 ············@gmail.com wrote:

> Thank you very much . It works now ! I've written far more complex
> code flawlessly , and these little things still evade me . It appears
> I'm still a nob . :))  .
> Anyway , lisp rocks , and so does this group .
>                                                       Dan .

The Lisp implementation might want to give
you a better error message.


Welcome to OpenMCL Version 1.1-pre-070512 (DarwinX8664)!
? (load "/tmp/wrong.lisp")
> Error: The function SEARCH is predefined in OpenMCL.
> While executing: CCL::REDEFINE-KERNEL-FUNCTION, in process listener(1).
> Type :GO to continue, :POP to abort, :R for a list of available restarts.
> If continued: Replace the definition of SEARCH.
> Type :? for other options.
1 > 






This is SBCL 1.0.9, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

...
* (load "/tmp/wrong.lisp")

...

STYLE-WARNING: redefining SEARCH in DEFUN

debugger invoked on a SYMBOL-PACKAGE-LOCKED-ERROR:
  Lock on package COMMON-LISP violated when setting fdefinition of SEARCH.
See also:
  The SBCL Manual, Node "Package Locks"
  The ANSI Standard, Section 11.1.2.1.2

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [CONTINUE      ] Ignore the package lock.
  1: [IGNORE-ALL    ] Ignore all package locks in the context of this operation.
  2: [UNLOCK-PACKAGE] Unlock the package.
  3: [ABORT         ] Exit debugger, returning to top level.

(PACKAGE-LOCK-VIOLATION #<PACKAGE "COMMON-LISP">)
0] 




LispWorks:

CL-USER 2 > (load *)
; Loading fasl file /private/tmp/wrong.xfasl

Error: Redefining function SEARCH visible from package COMMON-LISP.
  1 (continue) Redefine it anyway.
  2 Try loading /private/tmp/wrong.xfasl again.
  3 Give up loading /private/tmp/wrong.xfasl.
  4 Try loading another file instead of /private/tmp/wrong.xfasl.
  5 (abort) Return to level 0.
  6 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options

-- 
http://lispm.dyndns.org
From: Ari Johnson
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <m2bqcj8rxm.fsf@nibbler.theari.com>
············@gmail.com writes:

> (defun search (listy condition element)
> (if (null listy) nil
> (let ((c (funcall condition (car listy))))
> (if c (list (car listy) element c)
> (search (cdr listy) condition (+ 1 element))))))

Others have pointed out the real problem that you are running into,
but it appears that they're failing at their usual task: Telling you
that Common Lisp is a Lisp-2 and thus has a separate namespace for
variables and operators, so that you don't have to use silly names
like "listy" to avoid stepping on the availability of #'LIST.

(defun my-search (list condition element)
  (if (null list)
    nil
    (let ((c (funcall condition (car list))))
      (if c
        (list (car list) element c)
        (my-search (cdr list) condition (+ 1 element))))))

Of course, "condition" and "element" could use better names.  Your
variable condition (a) gives the term an overloaded meaning in Common
Lisp code, where it means what "exception" does in some other
languages and (b) is known as TEST in Common Lisp functions.  Your
variable element would better be known as "position" and should
probably have a default value or, better to avoid being fed garbage,
no opportunity for the user to supply a value.

(defun my-search (list test)
  (labels ((rec (list test position)
             (if (null list)
               nil
               (let ((result (funcall test (car list))))
                 (if result
                   (list (car list) position result)
                   (rec (cdr list) test (1+ position)))))))
    (rec list test 0)))

Another suggestion: Add a documentation string to describe what the
function does, including what it expects as input and what it returns
as output.  Your original version was not clear in these respects.
From: Ken Tilton
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <oU1Di.95$J34.10@newsfe12.lga>
Ari Johnson wrote:
> ············@gmail.com writes:
> 
> 
>>(defun search (listy condition element)
>>(if (null listy) nil
>>(let ((c (funcall condition (car listy))))
>>(if c (list (car listy) element c)
>>(search (cdr listy) condition (+ 1 element))))))
> 
> 
> Others have pointed out the real problem that you are running into,
> but it appears that they're failing at their usual task: Telling you
> that Common Lisp is a Lisp-2 and thus has a separate namespace for
> variables and operators, so that you don't have to use silly names
> like "listy" to avoid stepping on the availability of #'LIST.

Yeah, normally they get fried for that. We are letting them wear us down 
with their sheer numbers, people. Suck it up! All we have to is flame a 
few of them and they will all scurry off to find another language.

> 
> (defun my-search (list condition element)
>   (if (null list)
>     nil
>     (let ((c (funcall condition (car list))))
>       (if c
>         (list (car list) element c)
>         (my-search (cdr list) condition (+ 1 element))))))
> 
> Of course, "condition" and "element" could use better names.  Your
> variable condition (a) gives the term an overloaded meaning in Common
> Lisp code, where it means what "exception" does in some other
> languages and (b) is known as TEST in Common Lisp functions.  Your
> variable element would better be known as "position" and should
> probably have a default value or, better to avoid being fed garbage,
> no opportunity for the user to supply a value.

Oh, my, this is Lisp, we do not put on strait jackets to protect us from 
ourselves. &optional (element 0), not all that labels rigmarole.
> 
> (defun my-search (list test)
>   (labels ((rec (list test position)
>              (if (null list)

good lord, what is wrong with (when list...? Too verbose, actually, just 
iterate over the list, if it's null you'll get your lousy nil.

>                nil
>                (let ((result (funcall test (car list))))
>                  (if result
>                    (list (car list) position result)
>                    (rec (cdr list) test (1+ position)))))))
>     (rec list test 0)))

We also like to fry noobs for using recursion gratuitously.

(defun some-thing-pos (list test)
    (loop for e in list
	for pos upfrom 0
	for res = (funcall test e)
	when res return (list res e pos res))) ;; order to fit name

I must say, however, I am suspicous of the whole business, and would 
like to see the calling code so we can really rake this bum over the coals.

> 
> Another suggestion: Add a documentation string...

Documentation? Puh-leeze.

> to describe what the
> function does, 

God forbid the function name convey that. (Noobs may not be aware that 
SOME returns the result of the function parameter.)

kt

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut
From: Ken Tilton
Subject: Re: Can someone please explain me what's wrong with this code ?
Date: 
Message-ID: <rCxDi.5$vN5.2@newsfe12.lga>
Ken Tilton wrote:
> 
> (defun some-thing-pos (list test)
>    (loop for e in list
>     for pos upfrom 0
>     for res = (funcall test e)
>     when res return (list res e pos res))) ;; order to fit name

A little less loopy:

(defun some-thing-pos (list test)
    (loop for e in list
     for pos upfrom 0
     thereis (bwhen (res (funcall test e))
               (list res e pos res))))

BWHEN left as an exercise.

kt

-- 
http://www.theoryyalgebra.com/

"We are what we pretend to be." -Kurt Vonnegut