Page 1 of 1

Simple question about (format)

Posted: Thu Sep 16, 2010 6:19 pm
by ryanthejuggler
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:

Code: Select all

Welcome. Please enter your name.
NILwinifred
...as opposed to what I'd like, which is this:

Code: Select all

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)

Posted: Thu Sep 16, 2010 7:50 pm
by nuntius
Could you post the relevant snippet of your code? I don't remember seeing this problem.

Maybe this example will help?

Code: Select all

(defun read-name ()
  (format t "Welcome. Please enter your name.~%")
  (read-line))

Re: Simple question about (format)

Posted: Thu Sep 16, 2010 8:09 pm
by ryanthejuggler
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.

Code: Select all

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

Posted: Fri Sep 17, 2010 10:17 pm
by ryanthejuggler
Okay, I feel really foolish. The (print) statement... yeah... Case closed, sorry everybody *facepalm*

Re: Simple question about (format)

Posted: Sat Sep 18, 2010 6:02 am
by nuntius
No problem. As long as you're willing to learn, we're here to help.