Search code examples
lisp

write vs write-line in LISP


I am getting started with LISP and write the following program

(write-line "hello world")
(print "hello world print")
(write "hello world write")

for which I get the following output

hello world

"hello world print" "hello world write"

I guess write and print return string object so whats the type thats being returned by write-line why this didn't have quotations.

Link to my work-space


Solution

  • According to write-line/ write-string official documentation it returns its argument. What you see it the side effect (printing). Usually you will also see the return if top level in a REPL:

    > (write-line "hello world")
    ; hello world (printed)
    ;==> "hello world" (returned)
    

    Note that write is not limited to printing strings as they take any CL object and prin1, print, pprint, and princ are just write with some dynamic settings predefined.