emacs.d/clones/lisp/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node23.html

102 lines
5.7 KiB
HTML
Raw Normal View History

2022-08-26 19:11:35 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>2.2.2. Line Divisions</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Line Divisions">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html1796 HREF="node24.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1794 HREF="node21.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1788 HREF="node22.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1798 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1799 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html1797 HREF="node24.html"> Non-standard Characters</A>
<B>Up:</B> <A NAME=tex2html1795 HREF="node21.html"> Characters</A>
<B> Previous:</B> <A NAME=tex2html1789 HREF="node22.html"> Standard Characters</A>
<HR> <P>
<H2><A NAME=SECTION00622000000000000000>2.2.2. Line Divisions</A></H2>
<P>
The treatment of line divisions is one of the most difficult issues
in designing portable software, simply because there is so little agreement
among operating systems. Some use a single character to delimit lines;
the recommended ASCII character for this purpose is the line feed character
LF (also called the new line character, NL),
but some systems use the carriage
return character CR. Much more common is the two-character sequence
CR followed by LF. Frequently line divisions have no representation
as a character but are implicit in the structuring of a file into records,
each record containing a line of text. A deck of punched cards has this
structure, for example.
<P>
Common Lisp provides an abstract interface by requiring that there be a single
character, <tt>#\Newline</tt>, that within the language serves as a line
delimiter. (The language C has a similar requirement.)
An implementation of Common Lisp must translate between this internal
single-character representation and whatever external representation(s)
may be used.
<P>
<hr>
<b>Implementation note:</b> How the character called <tt>#\Newline</tt> is represented
internally is not specified here, but it is strongly suggested that
the ASCII LF character be used in Common Lisp implementations that use the
ASCII character encoding. The ASCII CR character is a workable,
but in most cases inferior, alternative.
<hr>
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
When the first edition was written it was not yet clear that UNIX would
become so widely accepted. The decision to represent
the line delimiter as a single character has proved to be a good one.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
The requirement that a line division be represented as a single character
has certain consequences. A character string
written in the middle of a program in such a way as to span more than
one line must contain exactly one character to represent each line division.
Consider this code fragment:
<P><pre>
(setq a-string &quot;This string
contains
forty-two characters.&quot;)
</pre><P>
Between <tt>g</tt> and <tt>c</tt> there must be exactly one character,
<tt>#\Newline</tt>; a two-character sequence, such as <tt>#\Return</tt> and then
<tt>#\Newline</tt>, is not acceptable, nor is the absence of a character.
The same is true between <tt>s</tt> and <tt>f</tt>.
<P>
When the character <tt>#\Newline</tt> is written to an output file,
the Common Lisp implementation must take the appropriate action
to produce a line division. This might involve writing out a
record or translating <tt>#\Newline</tt> to a CR/LF sequence.
<P>
<hr>
<b>Implementation note:</b> If an implementation uses the ASCII character encoding,
uses the CR/LF sequence externally to delimit lines,
uses LF to represent <tt>#\Newline</tt> internally, and supports <tt>#\Return</tt>
as a data object corresponding to the ASCII character CR, the
question arises as to what action to take when the program
writes out <tt>#\Return</tt> followed by <tt>#\Newline</tt>.
It should first be noted that <tt>#\Return</tt> is not a standard Common Lisp
character, and the action to be taken when <tt>#\Return</tt> is written out
is therefore not defined by the Common Lisp language. A plausible approach
is to buffer the <tt>#\Return</tt> character and suppress it if and only if the
next character is <tt>#\Newline</tt> (the net effect is to generate a CR/LF
sequence).
Another plausible
approach is simply to ignore
the difficulty and declare that writing <tt>#\Return</tt> and then
<tt>#\Newline</tt> results in the sequence CR/CR/LF in the output.
<hr>
<P>
<BR> <HR><A NAME=tex2html1796 HREF="node24.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1794 HREF="node21.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1788 HREF="node22.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1798 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1799 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html1797 HREF="node24.html"> Non-standard Characters</A>
<B>Up:</B> <A NAME=tex2html1795 HREF="node21.html"> Characters</A>
<B> Previous:</B> <A NAME=tex2html1789 HREF="node22.html"> Standard Characters</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>