Simple question about (format)

Discussion of Common Lisp
Post Reply
ryanthejuggler
Posts: 3
Joined: Thu Sep 16, 2010 6:12 pm

Simple question about (format)

Post by ryanthejuggler » Thu Sep 16, 2010 6:19 pm

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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Simple question about (format)

Post by nuntius » Thu Sep 16, 2010 7:50 pm

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

ryanthejuggler
Posts: 3
Joined: Thu Sep 16, 2010 6:12 pm

Re: Simple question about (format)

Post by ryanthejuggler » Thu Sep 16, 2010 8:09 pm

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

ryanthejuggler
Posts: 3
Joined: Thu Sep 16, 2010 6:12 pm

Re: Simple question about (format)

Post by ryanthejuggler » Fri Sep 17, 2010 10:17 pm

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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Simple question about (format)

Post by nuntius » Sat Sep 18, 2010 6:02 am

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

Post Reply