Page 1 of 1
problrm with a function
Posted: Sun May 30, 2010 10:34 pm
by nechalus
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 ?
Re: problrm with a function
Posted: Sun May 30, 2010 11:54 pm
by jerry
the form 'dolist' does not work with string,
i suggest you the library "split-sequence" to do your job!
Re: problrm with a function
Posted: Mon May 31, 2010 4:14 am
by Jasper
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.