Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LISP error in FORMAT function call

I wrote this code to write of a file:

(defun writefile (text filename)
  (with-open-file (stream filename :direction :output :if-exists :supersede
                   :if-does-not-exist :create)
    (format stream text)))

but if i execute, for example:

(writefile '(a b c) "foo.txt")

returns:

Error: In a call to FORMAT: (A B C) is not of type (OR STRING FUNCTION).

Why it shows me that error?

like image 358
Fred_2 Avatar asked Sep 13 '26 19:09

Fred_2


1 Answers

Your format call is wrong: the second argument should be either a string or a function (cf. the error message!)

You need to replace it with (format stream "~S" text) or just use prin1 or write.

like image 64
sds Avatar answered Sep 16 '26 13:09

sds