lispsetquotecoerce

Lisp Coerce and Set function explanation


I try to do this directly to the interpret:

(setf example (coerce "blablabla" 'list))

and works fine. Infact (car example) returns #\b

but if I try this:

(defun myfun (string) ( (setf example (coerce string 'list))))

(myfun "blablabla") 

I don't get the same!

How can I fix?


Solution

  • Remove the extra parentheses around the setf in the defun:

    (defun myfun (string)
      (setf example (coerce string 'list)))
    

    Now you'll get the same. Note that the outer parenthesis have meaning. In Lisp, either it is quoted, or must be a function call. If the first element is, as in this case, a list, it cannot be a function to call, hence the error.