diff options
| author | Richard M. Stallman | 1994-04-30 05:04:27 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-30 05:04:27 +0000 |
| commit | b664e4837ebc685962169d2c65cc787c6bf334f3 (patch) | |
| tree | 283f1e7c1faf2cbd9079040415e438a4df703802 | |
| parent | c567ac01779e2ae8e174ec6ca85a239beeff8f66 (diff) | |
| download | emacs-b664e4837ebc685962169d2c65cc787c6bf334f3.tar.gz emacs-b664e4837ebc685962169d2c65cc787c6bf334f3.zip | |
entered into RCS
| -rw-r--r-- | lispref/streams.texi | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/lispref/streams.texi b/lispref/streams.texi index 22c9c89ae33..6efa571ff9c 100644 --- a/lispref/streams.texi +++ b/lispref/streams.texi | |||
| @@ -48,7 +48,7 @@ usually produces a similar-looking object. For example, printing the | |||
| 48 | symbol @code{foo} produces the text @samp{foo}, and reading that text | 48 | symbol @code{foo} produces the text @samp{foo}, and reading that text |
| 49 | returns the symbol @code{foo}. Printing a list whose elements are | 49 | returns the symbol @code{foo}. Printing a list whose elements are |
| 50 | @code{a} and @code{b} produces the text @samp{(a b)}, and reading that | 50 | @code{a} and @code{b} produces the text @samp{(a b)}, and reading that |
| 51 | text produces a list (but not the same list) with elements are @code{a} | 51 | text produces a list (but not the same list) with elements @code{a} |
| 52 | and @code{b}. | 52 | and @code{b}. |
| 53 | 53 | ||
| 54 | However, these two operations are not precisely inverses. There are | 54 | However, these two operations are not precisely inverses. There are |
| @@ -127,7 +127,7 @@ A symbol as input stream is equivalent to the symbol's function | |||
| 127 | definition (if any). | 127 | definition (if any). |
| 128 | @end table | 128 | @end table |
| 129 | 129 | ||
| 130 | Here is an example of reading from a stream which is a buffer, showing | 130 | Here is an example of reading from a stream that is a buffer, showing |
| 131 | where point is located before and after: | 131 | where point is located before and after: |
| 132 | 132 | ||
| 133 | @example | 133 | @example |
| @@ -154,8 +154,8 @@ This is the@point{} contents of foo. | |||
| 154 | @end example | 154 | @end example |
| 155 | 155 | ||
| 156 | @noindent | 156 | @noindent |
| 157 | Note that the first read skips a space at the beginning of the buffer. | 157 | Note that the first read skips a space. Reading skips any amount of |
| 158 | Reading skips any amount of whitespace preceding the significant text. | 158 | whitespace preceding the significant text. |
| 159 | 159 | ||
| 160 | In Emacs 18, reading a symbol discarded the delimiter terminating the | 160 | In Emacs 18, reading a symbol discarded the delimiter terminating the |
| 161 | symbol. Thus, point would end up at the beginning of @samp{contents} | 161 | symbol. Thus, point would end up at the beginning of @samp{contents} |
| @@ -164,7 +164,7 @@ it correctly handles input such as @samp{bar(foo)}, where the delimiter | |||
| 164 | that ends one object is needed as the beginning of another object. | 164 | that ends one object is needed as the beginning of another object. |
| 165 | 165 | ||
| 166 | Here is an example of reading from a stream that is a marker, | 166 | Here is an example of reading from a stream that is a marker, |
| 167 | initialized to point at the beginning of the buffer shown. The value | 167 | initially positioned at the beginning of the buffer shown. The value |
| 168 | read is the symbol @code{This}. | 168 | read is the symbol @code{This}. |
| 169 | 169 | ||
| 170 | @example | 170 | @example |
| @@ -185,7 +185,7 @@ This is the contents of foo. | |||
| 185 | @end group | 185 | @end group |
| 186 | @group | 186 | @group |
| 187 | m | 187 | m |
| 188 | @result{} #<marker at 6 in foo> ;; @r{After the first space.} | 188 | @result{} #<marker at 5 in foo> ;; @r{Before the first space.} |
| 189 | @end group | 189 | @end group |
| 190 | @end example | 190 | @end example |
| 191 | 191 | ||
| @@ -216,7 +216,7 @@ Lisp expression: @kbd{23 @key{RET}} | |||
| 216 | Finally, here is an example of a stream that is a function, named | 216 | Finally, here is an example of a stream that is a function, named |
| 217 | @code{useless-stream}. Before we use the stream, we initialize the | 217 | @code{useless-stream}. Before we use the stream, we initialize the |
| 218 | variable @code{useless-list} to a list of characters. Then each call to | 218 | variable @code{useless-list} to a list of characters. Then each call to |
| 219 | the function @code{useless-stream} obtains the next characters in the list | 219 | the function @code{useless-stream} obtains the next character in the list |
| 220 | or unreads a character by adding it to the front of the list. | 220 | or unreads a character by adding it to the front of the list. |
| 221 | 221 | ||
| 222 | @example | 222 | @example |
| @@ -246,15 +246,15 @@ Now we read using the stream thus constructed: | |||
| 246 | 246 | ||
| 247 | @group | 247 | @group |
| 248 | useless-list | 248 | useless-list |
| 249 | @result{} (41) | 249 | @result{} (40 41) |
| 250 | @end group | 250 | @end group |
| 251 | @end example | 251 | @end example |
| 252 | 252 | ||
| 253 | @noindent | 253 | @noindent |
| 254 | Note that the close parenthesis remains in the list. The reader has | 254 | Note that the open and close parentheses remains in the list. The Lisp |
| 255 | read it, discovered that it ended the input, and unread it. Another | 255 | reader encountered the open parenthesis, decided that it ended the |
| 256 | attempt to read from the stream at this point would get an error due to | 256 | input, and unread it. Another attempt to read from the stream at this |
| 257 | the unmatched close parenthesis. | 257 | point would read @samp{()} and return @code{nil}. |
| 258 | 258 | ||
| 259 | @defun get-file-char | 259 | @defun get-file-char |
| 260 | This function is used internally as an input stream to read from the | 260 | This function is used internally as an input stream to read from the |
| @@ -274,7 +274,7 @@ defaults to the value of @code{standard-input}. | |||
| 274 | 274 | ||
| 275 | @kindex end-of-file | 275 | @kindex end-of-file |
| 276 | An @code{end-of-file} error is signaled if reading encounters an | 276 | An @code{end-of-file} error is signaled if reading encounters an |
| 277 | unterminated list, vector or string. | 277 | unterminated list, vector, or string. |
| 278 | 278 | ||
| 279 | @defun read &optional stream | 279 | @defun read &optional stream |
| 280 | This function reads one textual Lisp expression from @var{stream}, | 280 | This function reads one textual Lisp expression from @var{stream}, |
| @@ -288,10 +288,10 @@ This function reads the first textual Lisp expression from the text in | |||
| 288 | and whose @sc{cdr} is an integer giving the position of the next | 288 | and whose @sc{cdr} is an integer giving the position of the next |
| 289 | remaining character in the string (i.e., the first one not read). | 289 | remaining character in the string (i.e., the first one not read). |
| 290 | 290 | ||
| 291 | If @var{start} is supplied, then reading begins at index @var{start} in the | 291 | If @var{start} is supplied, then reading begins at index @var{start} in |
| 292 | string (where the first character is at index 0). If @var{end} is also | 292 | the string (where the first character is at index 0). If @var{end} is |
| 293 | supplied, then reading stops at that index as if the rest of the string | 293 | also supplied, then reading stops just before that index, as if the rest |
| 294 | were not there. | 294 | of the string were not there. |
| 295 | 295 | ||
| 296 | For example: | 296 | For example: |
| 297 | 297 | ||
| @@ -313,7 +313,7 @@ For example: | |||
| 313 | @group | 313 | @group |
| 314 | ;; @r{Read starting at the second character.} | 314 | ;; @r{Read starting at the second character.} |
| 315 | (read-from-string "(list 112)" 1) | 315 | (read-from-string "(list 112)" 1) |
| 316 | @result{} (list . 6) | 316 | @result{} (list . 5) |
| 317 | @end group | 317 | @end group |
| 318 | @group | 318 | @group |
| 319 | ;; @r{Read starting at the seventh character,} | 319 | ;; @r{Read starting at the seventh character,} |
| @@ -347,7 +347,7 @@ Point advances as characters are inserted. | |||
| 347 | @item @var{marker} | 347 | @item @var{marker} |
| 348 | @cindex marker output stream | 348 | @cindex marker output stream |
| 349 | The output characters are inserted into the buffer that @var{marker} | 349 | The output characters are inserted into the buffer that @var{marker} |
| 350 | points into, at the marker position. The position advances as | 350 | points into, at the marker position. The marker position advances as |
| 351 | characters are inserted. The value of point in the buffer has no effect | 351 | characters are inserted. The value of point in the buffer has no effect |
| 352 | on printing when the stream is a marker. | 352 | on printing when the stream is a marker. |
| 353 | 353 | ||
| @@ -373,6 +373,10 @@ A symbol as output stream is equivalent to the symbol's function | |||
| 373 | definition (if any). | 373 | definition (if any). |
| 374 | @end table | 374 | @end table |
| 375 | 375 | ||
| 376 | Many of the valid output streams are also valid as input streams. The | ||
| 377 | difference between input and output streams is therefore mostly one of | ||
| 378 | how you use a Lisp object, not a distinction of types of object. | ||
| 379 | |||
| 376 | Here is an example of a buffer used as an output stream. Point is | 380 | Here is an example of a buffer used as an output stream. Point is |
| 377 | initially located as shown immediately before the @samp{h} in | 381 | initially located as shown immediately before the @samp{h} in |
| 378 | @samp{the}. At the end, point is located directly before that same | 382 | @samp{the}. At the end, point is located directly before that same |
| @@ -399,11 +403,11 @@ This is t | |||
| 399 | @end example | 403 | @end example |
| 400 | 404 | ||
| 401 | Now we show a use of a marker as an output stream. Initially, the | 405 | Now we show a use of a marker as an output stream. Initially, the |
| 402 | marker points in buffer @code{foo}, between the @samp{t} and the | 406 | marker is in buffer @code{foo}, between the @samp{t} and the @samp{h} in |
| 403 | @samp{h} in the word @samp{the}. At the end, the marker has been | 407 | the word @samp{the}. At the end, the marker has advanced over the |
| 404 | advanced over the inserted text so that it still points before the same | 408 | inserted text so that it remains positioned before the same @samp{h}. |
| 405 | @samp{h}. Note that the location of point, shown in the usual fashion, | 409 | Note that the location of point, shown in the usual fashion, has no |
| 406 | has no effect. | 410 | effect. |
| 407 | 411 | ||
| 408 | @example | 412 | @example |
| 409 | @group | 413 | @group |
| @@ -490,6 +494,10 @@ Now we can put the output in the proper order by reversing the list: | |||
| 490 | @end group | 494 | @end group |
| 491 | @end example | 495 | @end example |
| 492 | 496 | ||
| 497 | @noindent | ||
| 498 | Calling @code{concat} converts the list to a string so you can see its | ||
| 499 | contents more clearly. | ||
| 500 | |||
| 493 | @node Output Functions | 501 | @node Output Functions |
| 494 | @section Output Functions | 502 | @section Output Functions |
| 495 | 503 | ||
| @@ -503,9 +511,9 @@ Now we can put the output in the proper order by reversing the list: | |||
| 503 | output when necessary so that it can be read properly. The quoting | 511 | output when necessary so that it can be read properly. The quoting |
| 504 | characters used are @samp{"} and @samp{\}; they distinguish strings from | 512 | characters used are @samp{"} and @samp{\}; they distinguish strings from |
| 505 | symbols, and prevent punctuation characters in strings and symbols from | 513 | symbols, and prevent punctuation characters in strings and symbols from |
| 506 | being taken as delimiters. @xref{Printed Representation}, for full | 514 | being taken as delimiters when reading. @xref{Printed Representation}, |
| 507 | details. You specify quoting or no quoting by the choice of printing | 515 | for full details. You specify quoting or no quoting by the choice of |
| 508 | function. | 516 | printing function. |
| 509 | 517 | ||
| 510 | If the text is to be read back into Lisp, then it is best to print | 518 | If the text is to be read back into Lisp, then it is best to print |
| 511 | with quoting characters to avoid ambiguity. Likewise, if the purpose is | 519 | with quoting characters to avoid ambiguity. Likewise, if the purpose is |
| @@ -558,9 +566,9 @@ characters are used. @code{print} returns @var{object}. For example: | |||
| 558 | 566 | ||
| 559 | @defun prin1 object &optional stream | 567 | @defun prin1 object &optional stream |
| 560 | This function outputs the printed representation of @var{object} to | 568 | This function outputs the printed representation of @var{object} to |
| 561 | @var{stream}. It does not print any spaces or newlines to separate | 569 | @var{stream}. It does not print newlines to separate output as |
| 562 | output as @code{print} does, but it does use quoting characters just | 570 | @code{print} does, but it does use quoting characters just like |
| 563 | like @code{print}. It returns @var{object}. | 571 | @code{print}. It returns @var{object}. |
| 564 | 572 | ||
| 565 | @example | 573 | @example |
| 566 | @group | 574 | @group |
| @@ -686,7 +694,7 @@ In the second expression, the local binding of | |||
| 686 | @cindex printing limits | 694 | @cindex printing limits |
| 687 | The value of this variable is the maximum number of elements of a list | 695 | The value of this variable is the maximum number of elements of a list |
| 688 | that will be printed. If a list being printed has more than this many | 696 | that will be printed. If a list being printed has more than this many |
| 689 | elements, then it is abbreviated with an ellipsis. | 697 | elements, it is abbreviated with an ellipsis. |
| 690 | 698 | ||
| 691 | If the value is @code{nil} (the default), then there is no limit. | 699 | If the value is @code{nil} (the default), then there is no limit. |
| 692 | 700 | ||
| @@ -705,7 +713,7 @@ If the value is @code{nil} (the default), then there is no limit. | |||
| 705 | 713 | ||
| 706 | @defvar print-level | 714 | @defvar print-level |
| 707 | The value of this variable is the maximum depth of nesting of | 715 | The value of this variable is the maximum depth of nesting of |
| 708 | parentheses that will be printed. Any list or vector at a depth | 716 | parentheses and brackets when printed. Any list or vector at a depth |
| 709 | exceeding this limit is abbreviated with an ellipsis. A value of | 717 | exceeding this limit is abbreviated with an ellipsis. A value of |
| 710 | @code{nil} (which is the default) means no limit. | 718 | @code{nil} (which is the default) means no limit. |
| 711 | 719 | ||