Strings, Characters and I/O

Because read parses s-expressions, Lisp data files are trivial to read and write: configuration, saved state, and serialization often just use s-expressions (like Clojure's EDN).

(string-append "Hello, " "World")       ; "Hello, World"
(string-length "Lisp")                  ; 4
(substring "Hello" 1 3)                 ; "el"
(string-upcase "lisp")                  ; "LISP"
(string->number "42")                   ; 42
(number->string 42)                     ; "42"
(string->list "abc")                    ; (#\a #\b #\c)
(list->string (list #\a #\b))           ; "ab"
(string=? "a" "a")                      ; #t
(char->integer #\A)                     ; 65
(display "no quotes")  (write "with quotes")  (newline)

;; Files (R7RS)
(call-with-output-file "out.txt"
  (lambda (port) (write-string "Hello file\n" port)))
(call-with-input-file "out.txt"
  (lambda (port) (read-line port)))     ; "Hello file"
(define datum (read (open-input-string "(1 2 (3))")))   ; read parses s-expressions!
;; Common Lisp
(format nil "~a has ~d items" "cart" 3)         ; "cart has 3 items"
(with-open-file (s "out.txt" :direction :output :if-exists :supersede)
  (format s "Hello file~%"))
;; Clojure
(str "Hello, " "World")
(clojure.string/upper-case "lisp")
(clojure.string/split "a,b,c" #",")
(spit "out.txt" "Hello file\n")
(slurp "out.txt")
(format "%s has %d items" "cart" 3)