Example
An example of a C printf call is the following:
Using Common Lisp, this is equivalent to:
(format t "Color ~A, number1 ~D, number2 ~5,'0D, hex ~X, float ~5,2F, unsigned value ~D.~%" "red" 123456 89 255 3.14 250) ;; ⇒ Color red, number1 123456, number2 00089, hex FF, float 3.14, unsigned value 250.Another example would be to print every element of list delimited with commas, which can be used using the ~{, ~^ and ~} directives:
(let ((groceries '(eggs bread butter carrots))) (format t "~{~A~^, ~}.~%" groceries) ; Prints in uppercase (format t "~@(~{~A~^, ~}~).~%" groceries)) ; Capitalizes output ;; ⇒ EGGS, BREAD, BUTTER, CARROTS. ;; ⇒ Eggs, bread, butter, carrots.Read more about this topic: Format (Common Lisp)
Famous quotes containing the word example:
“Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.”
—Marcel Proust (18711922)