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.

Simple question about (format)

5 posts · 999 views

Hello all,
I'm trying to write a simple program, but I can't seem to get around the fact that (format) returns NIL. Therefore my program output always looks like this:
Welcome. Please enter your name.
NILwinifred
...as opposed to what I'd like, which is this:
Welcome. Please enter your name.
winifred
I know that this is a very basic question, but every time I Google "lisp format nil" or any combination thereof (believe me, I've probably tried them all) it comes up with every Lisp program out there, because they all use (format) and NIL!\
Thank you so much for your help.
~RAM

Re: Simple question about (format)

Could you post the relevant snippet of your code? I don't remember seeing this problem.

Maybe this example will help?
(defun read-name ()
  (format t "Welcome. Please enter your name.~%")
  (read-line))

Re: Simple question about (format)

I see how your program works, and I'll modify mine to be more like that, perhaps having the user enter symbols instead of functions.

Here's my code in case you're curious though. "phrases.txt" is one big long parenthesized list of sayings.
(progn
(setq list (read (open "phrases.txt")))
(defun ok () (format t "~A." (nth (random (length list)) list)))
(format t "Welcome to Fortune Teller.~%Type (ok) for a fortune or (bye) to exit.~%")
(loop (print (eval (read)))))

Re: Simple question about (format)

Okay, I feel really foolish. The (print) statement... yeah... Case closed, sorry everybody *facepalm*

Re: Simple question about (format)

No problem. As long as you're willing to learn, we're here to help.