problrm with a function

Discussion of Common Lisp
Post Reply
nechalus
Posts: 3
Joined: Tue May 25, 2010 4:09 pm

problrm with a function

Post by nechalus » Sun May 30, 2010 10:34 pm

Hello
I am trying to load a function lisp.
But there is an error :

(setf base nil)
Function : (defun find-wrong-word (str)
(dolist (word base)
(when (search word str :test #'string-equal)
(return-from find-wrong-word t))))

Error : Warning: Syntactic warning for form BASE:
BASE assumed special.
I don't understand where is the problem ?

jerry
Posts: 1
Joined: Sun May 16, 2010 10:02 pm

Re: problrm with a function

Post by jerry » Sun May 30, 2010 11:54 pm

the form 'dolist' does not work with string,

i suggest you the library "split-sequence" to do your job!

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Re: problrm with a function

Post by Jasper » Mon May 31, 2010 4:14 am

SETQ and SETF shouldn't define variables, they're for changing them. Afaik CL does make special variables for you. Variables are defined from various forms like LET, DEFUN, destructuring-bind etcetera. Special variables are created with DEFVAR and defparameter, in the variables section of PCL you can read about them. Essentially they are variables that are automatically added to the arguments when they have an effect.

Looks to me like #'string is not the test you want. Maybe #'char=, but the default #'eql would work aswel.

Code: Select all

(defun find-wrong-word (str base)
  (dolist (word base)
    (when (search word str)
      (return-from find-wrong-word t))))
Seems to work. I'd write:(alexandria):

Code: Select all

(defun find-wrong-word (str base)
  (find-if (alexandria:rcurry #'search str) base))
rcurry takes a function and arguments, and outputs a function with the arguments of the right side filled.(curry does it for left) Minor difference here is that it returns the found string.

Post Reply