(princ (concatenate 'string "hello, " "world"))
;; => hello, world
;;
;; "hello, world"
concatenate
can be used with different types, we need to specify the output type with the'string
symbol.
(princ (format nil "1 + 1 = ~a" (+ 1 1)))
;; => 1 + 1 = 2
;;
;; "1 + 1 = 2"
format
is a function for creating formatted stringsnil
tellsformat
to evaluate to the string it creates~a
is a format directive. It prints the next argument toformat
_a_esthetically.- All
format
directives start with~
(format t "~a" (/ 4.0 5.0))
;; => 0.8
;;
;; NIL
- floating point numbers have a
.
in them - when the second argument to
format
ist
it prints the string to standard out - in this case
format
evaluates tonil
(+ 1/2 1/4)
;; => 3/4
- Lisp has rational numbers as a separate type - they are written with a
/
between the numerator and the denomenator.
(and t nil)
;; => NIL
(and "ada" 5 "alonzo")
;; => "alonzo"
(and)
;; => T
(or t nil)
;; => T
(or nil "lucy" nil)
;; => "barry"
(or)
;; => NIL
(not nil)
;; => T
(not "amy")
;; => NIL
- There is no true or false - only
t
andnil
t
andnil
are special symbols; they always evaluate to themselves- anything that's not
nil
is treated as true! and
andor
can take multiple valuesand
returns the firstnil
or the last non-nil
argumentor
returns the first non-nil
argumentnot
will returnnil
for all non-nil
values, andt
fornil
Common Lisp Hyperspec: FORMAT Common Lisp Hyperspec: Formatted output Practical Common Lisp: A Few Format Recipes