2

I'm new to lisp programming and i was wondering how do you output strings without quotes and without returning an object (that includes not returning a nil) like most languages?

std::cout<<"Hello world\n"; 

I know the format t function does that but it still returns nil isn't there a way to output without nil and quotes? Is it possible?

Can someone point me to Lisp tutorials like this or this but with more detailed documentation and explanations?

9
  • 2
    FORMAT does not output NIL additionally. If you have a question, please show code, an example and the actual description of the desired behavior and a description of the error. Don't forget the code... Commented Mar 24, 2018 at 15:35
  • Well I want to print only and nothing but Hello world!without quotes and without nil If I type (format t "Hello world")-this will output Hello world with nil but if I do (format nil "Hello world")-it will output "Hello world" I'm asking if there's a way to output only Hello world? Commented Mar 24, 2018 at 15:43
  • What's wrong with FORMAT? You need to show what you are doing. We can't guess your code. Commented Mar 24, 2018 at 15:44
  • FORMAT NIL does output nothing. It returns a string. Commented Mar 24, 2018 at 15:46
  • but with quotes Commented Mar 24, 2018 at 15:48

1 Answer 1

13

The REPL prints the value of each expression it executes

If you use the READ EVAL PRINT LOOP, the REPL will print the result. That's why it is called Read Eval Print Loop.

But output functions themselves will not print their result.

CL-USER 1 > (format t "hello") hello ; <- printed by FORMAT NIL ; <- printed by the REPL CL-USER 2 > (format t "world") world ; <- printed by FORMAT NIL ; <- printed by the REPL 

Now combine the above:

CL-USER 3 > (defun foo () (format t "hello") (format t "world")) FOO CL-USER 4 > (foo) helloworld ; <- printed by two FORMAT statements ; as you can see the FORMAT statement did not print a value NIL ; <- the return value of (foo) printed by the REPL 

If you return no value, the REPL will print no value.

CL-USER 5 > (defun foo () (format t "hello") (format t "world") (values)) FOO CL-USER 6 > (foo) helloworld ; <- printed by two FORMAT statements ; <- no return value -> nothing printed by the REPL 

You can execute Lisp code without a REPL

If you use Lisp without a REPL, no values are printed anyway:

$ sbcl --noinform --eval '(format t "hello world~%")' --eval '(quit)' hello world $ 

Alternatively you can have Lisp execute a Lisp file:

$ cat foo.lisp (format t "helloworld~%") $ sbcl --script foo.lisp helloworld $ 

The actual command lines are implementation specific.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer! This is the first time I encounter REPL.And you did answer my question(which I am grateful) can you point me to some detailed documentation please for REPL and for everything if not can you recommend books? Thank you!
@jakHunter: free beginner books: cs.cmu.edu/~dst/LispBook and gigamonkeys.com/book
As another option one can make an executable: sbcl --no-userinit --load foo.lisp --eval "(sb-ext:save-lisp-and-die \"a.out\" :toplevel 'foo :executable t)"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.