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.

Newbie: How do I print/format?

6 posts · 1220 views

Current reference: http://www.gigamonkeys.com/book/lather- ... -repl.html
Installation guide: http://www.osix.net/modules/article/?id=912

The first link gives this hello-world program:
(defun hello-world ()
  (format t "Hello, world!"))
Whether that statement is wrapped in a function or not, all it does is return NIL on my setup. Maybe it's because I'm using a different compiler (Clisp)?

The best I managed was to get FORMAT to return the given string (the same thing PRINT does):
(format nil "Hello, world!"))
Calling this function only prints "G":
defun hello-world ()
  (format nil "Hello, world!")
  (print "F")
  "G")
Did I miss something...? Thanks.
I'm off my grokker.
- Chris

Re: Newbie: How do I print/format?

Jesdisciple wrote:Whether that statement is wrapped in a function or not, all it does is return NIL on my setup.
In Common Lisp there are no statements, there are only expressions. Which means that everything has to return something (well, more or less), and usually a side-effecting function, like (format t ...) will return NIL. If you want to print something, why are you concerned with return value?

Usually code in Lisp is run from the REPL, which is Read-Eval-Print Loop, and it will print results of expressions which forms entered into return, but that is not relevant for printing in general. Anyway, on my Clisp:
[1]> (defun hello-world ()
  (format t "Hello, world!"))
HELLO-WORLD
[2]> (hello-world)
Hello, world!
NIL
Where the line before last is the line printed by format, and the last one is the return value printed by REPL. What is you problem, exactly?

EDIT: Oh, I see the installation guide you are using also explains Emacs/Slime setup, which is good. In that setup the output from side effecting printing will go to *inferior-lisp* buffer by default. You can get all output in REPL buffer by putting in file ~/.swank.lisp
(SETF SWANK:*GLOBALLY-REDIRECT-IO* T)
Case is not important.

EDIT 2: Also forgot to mention that, unless the situation improved recently, Common Lisp packages in distribution repositories are usually really old. I would recommend using clbuild to get them, starting with slime.

Re: Newbie: How do I print/format?

Ah, so there it is! Many thanks.

When I used the line you gave, it made *inferior-lisp* into the REPL rather than putting output in *slime-repl clisp*. Is this the intended effect? (It is certainly better than what I had, just not what I expected.)

I shall now write the expression "no statements in Lisp" 1000 times to the REPL.
I'm off my grokker.
- Chris

Re: Newbie: How do I print/format?

Jesdisciple wrote:When I used the line you gave, it made *inferior-lisp* into the REPL rather than putting output in *slime-repl clisp*. Is this the intended effect? (It is certainly better than what I had, just not what I expected.)
That is not what was intended, and not what happens on my system. It depends on the version of Slime you are using I think... at some point REPL was moved to optional modules, which means you need (slime-setup '(slime-repl)) in your .emacs, or even better (slime-setup '(slime-fancy)), rather than (slime-setup) alone, which configures the slime to not use any contribs. I have in fact (slime-setup '(slime-fancy slime-autodoc slime-asdf slime-banner slime-indentation)), but some of that is probably redundant.

Re: Newbie: How do I print/format?

Apologies for not responding sooner. I thought I had auto-subscribe on.

Wow, you're right: Ubuntu's repo'd Slime is way out of date. I ran into problems with its implementation of the input functions earlier.

Oh, and sorry for not even mentioning the REPL in my OP. That the problem was related more to it than to clisp itself should have occurred to me.
I'm off my grokker.
- Chris