This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

problrm with a function

3 posts · 841 views

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

the form 'dolist' does not work with string,

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

Re: problrm with a function

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.
(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):
(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.