195
To slightly confuse matters, most other I/O functions also accept T
and NIL
as T
designates the bidirectional stream *TERMINAL-IO*
, while NIL
designates *STANDARD-OUTPUT*
as an output stream and *STANDARD-INPUT*
as an input stream.
196
This variant on the ~C
directive makes more sense on platforms like the Lisp Machines where key press events were represented by Lisp characters.
197
Technically, if the argument isn't a real number, ~F
is supposed to format it as if by the ~D
directive, which in turn behaves like the ~A
directive if the argument isn't a number, but not all implementations get this right.
198
Well, that's what the language standard says. For some reason, perhaps rooted in a common ancestral code base, several Common Lisp implementations don't implement this aspect of the ~F
directive correctly.
199
f you find 'I saw zero elves' to be a bit clunky, you could use a slightly more elaborate format string that makes another use of ~:*
like this:
(format nil 'I saw ~[no~:;~:*~r~] el~:*~[ves~;f~:;ves~].' 0) ==> 'I saw no elves.'
(format nil 'I saw ~[no~:;~:*~r~] el~:*~[ves~;f~:;ves~].' 1) ==> 'I saw one elf.'
(format nil 'I saw ~[no~:;~:*~r~] el~:*~[ves~;f~:;ves~].' 2) ==> 'I saw two elves.'
200
This kind of problem can arise when trying to localize an application and translate human-readable messages into different languages. FORMAT
can help with some of these problems but is by no means a full-blown localization system.
201
202
203
In this respect, a condition is a lot like an exception in Java or Python except not all conditions represent an error or
204
In some Common Lisp implementations, conditions are defined as subclasses of STANDARD-OBJECT
, in which case SLOT- VALUE
, MAKE-INSTANCE
, and INITIALIZE-INSTANCE
will work, but it's not portable to rely on it.
205
The compiler may complain if the parameter is never used. You can silence that warning by adding a declaration (declare (ignore c))
as the first expression in the LAMBDA
body.
206
Of course, if IF
wasn't a special operator but some other conditional form, such as COND
, was, you could build IF
as a macro. Indeed, in many Lisp dialects, starting with McCarthy's original Lisp, COND
was the primitive conditional evaluation operator.