diff options
| author | Nicolas Petton | 2015-09-28 22:18:26 +0200 |
|---|---|---|
| committer | Nicolas Petton | 2015-09-28 22:18:26 +0200 |
| commit | f6e1f158f0517cd2520eae2c54065adfd42a8925 (patch) | |
| tree | f446fe062b4fa7ed9b9304973018e5f7402cd53c | |
| parent | f0b71429b9fbfb5dc5a561321de42a39fc176809 (diff) | |
| download | emacs-f6e1f158f0517cd2520eae2c54065adfd42a8925.tar.gz emacs-f6e1f158f0517cd2520eae2c54065adfd42a8925.zip | |
Add documentation for seq.el
* doc/lispref/sequences.texi: Add documentation regarding extending
seq.el, as well as missing documentation for seq-elt, seq-length, seq-p,
seq-do and seq-map.
| -rw-r--r-- | doc/lispref/sequences.texi | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 2dc494aec5d..0a6f4c6623c 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi | |||
| @@ -72,6 +72,7 @@ string, bool-vector, or char-table, @code{nil} otherwise. | |||
| 72 | @cindex vector length | 72 | @cindex vector length |
| 73 | @cindex sequence length | 73 | @cindex sequence length |
| 74 | @cindex char-table length | 74 | @cindex char-table length |
| 75 | @anchor{Definition of length} | ||
| 75 | This function returns the number of elements in @var{sequence}. If | 76 | This function returns the number of elements in @var{sequence}. If |
| 76 | @var{sequence} is a dotted list, a @code{wrong-type-argument} error is | 77 | @var{sequence} is a dotted list, a @code{wrong-type-argument} error is |
| 77 | signaled. Circular lists may cause an infinite loop. For a | 78 | signaled. Circular lists may cause an infinite loop. For a |
| @@ -113,6 +114,7 @@ since @code{length} only counts the number of characters, but does not | |||
| 113 | account for the display width of each character. | 114 | account for the display width of each character. |
| 114 | 115 | ||
| 115 | @defun elt sequence index | 116 | @defun elt sequence index |
| 117 | @anchor{Definition of elt} | ||
| 116 | @cindex elements of sequences | 118 | @cindex elements of sequences |
| 117 | This function returns the element of @var{sequence} indexed by | 119 | This function returns the element of @var{sequence} indexed by |
| 118 | @var{index}. Legitimate values of @var{index} are integers ranging | 120 | @var{index}. Legitimate values of @var{index} are integers ranging |
| @@ -431,6 +433,57 @@ you pass as an argument. Unless otherwise stated, the result is a | |||
| 431 | sequence of the same type as the input. For those functions that take | 433 | sequence of the same type as the input. For those functions that take |
| 432 | a predicate, this should be a function of one argument. | 434 | a predicate, this should be a function of one argument. |
| 433 | 435 | ||
| 436 | The @file{seq.el} library can be extended to work with additional | ||
| 437 | types of sequential data-structures. For that purpose, all functions | ||
| 438 | are defined using @code{cl-defgeneric}. | ||
| 439 | |||
| 440 | @defun seq-elt sequence index | ||
| 441 | This function the element at the index @var{index} in | ||
| 442 | @var{sequence}. @var{index} can be an integer from zero up to the | ||
| 443 | length of @var{sequence} minus one. For out-of-range values on | ||
| 444 | built-in sequence types, @code{seq-elt} behaves like @code{elt}. | ||
| 445 | @xref{Definition of elt}. | ||
| 446 | |||
| 447 | @example | ||
| 448 | @group | ||
| 449 | (seq-elt [1 2 3 4] 2) | ||
| 450 | @result{} 3 | ||
| 451 | @end group | ||
| 452 | |||
| 453 | @code{seq-elt} returns settable places using @code{setf}. | ||
| 454 | |||
| 455 | @group | ||
| 456 | (setq vec [1 2 3 4]) | ||
| 457 | (setf (seq-elt vec 2) 5) | ||
| 458 | vec | ||
| 459 | @result{} [1 2 5 4] | ||
| 460 | @end group | ||
| 461 | @end example | ||
| 462 | @end defun | ||
| 463 | |||
| 464 | @defun seq-length sequence | ||
| 465 | This function returns the number of elements in @var{sequence}. For | ||
| 466 | built-in sequence types, @code{seq-length} behaves like @code{length}. | ||
| 467 | @xref{Definition of length}. | ||
| 468 | @end defun | ||
| 469 | |||
| 470 | @defun seq-p sequence | ||
| 471 | This function returns non-@code{nil} if @var{sequence} is a sequence | ||
| 472 | (a list or array), or any additional type of sequence defined via | ||
| 473 | @file{seq.el} generic functions. | ||
| 474 | |||
| 475 | @example | ||
| 476 | @group | ||
| 477 | (seq-p [1 2]) | ||
| 478 | @result{} t | ||
| 479 | @end group | ||
| 480 | @group | ||
| 481 | (seq-p 2) | ||
| 482 | @result{} nil | ||
| 483 | @end group | ||
| 484 | @end example | ||
| 485 | @end defun | ||
| 486 | |||
| 434 | @defun seq-drop sequence n | 487 | @defun seq-drop sequence n |
| 435 | This function returns all but the first @var{n} (an integer) | 488 | This function returns all but the first @var{n} (an integer) |
| 436 | elements of @var{sequence}. If @var{n} is negative or zero, | 489 | elements of @var{sequence}. If @var{n} is negative or zero, |
| @@ -497,6 +550,28 @@ starting from the first one for which @var{predicate} returns @code{nil}. | |||
| 497 | @end example | 550 | @end example |
| 498 | @end defun | 551 | @end defun |
| 499 | 552 | ||
| 553 | @defun seq-do function sequence | ||
| 554 | This function applies @var{function} to each element of | ||
| 555 | @var{sequence} in turn (presumably for side effects) and returns | ||
| 556 | @var{sequence}. | ||
| 557 | @end defun | ||
| 558 | |||
| 559 | @defun seq-map function sequence | ||
| 560 | This function returns the result of applying @var{function} to each | ||
| 561 | element of @var{sequence}. The returned value is a list. | ||
| 562 | |||
| 563 | @example | ||
| 564 | @group | ||
| 565 | (seq-map #'1+ '(2 4 6)) | ||
| 566 | @result{} (3 5 7) | ||
| 567 | @end group | ||
| 568 | @group | ||
| 569 | (seq-map #'symbol-name [foo bar]) | ||
| 570 | @result{} ("foo" "bar") | ||
| 571 | @end group | ||
| 572 | @end example | ||
| 573 | @end defun | ||
| 574 | |||
| 500 | @defun seq-filter predicate sequence | 575 | @defun seq-filter predicate sequence |
| 501 | @cindex filtering sequences | 576 | @cindex filtering sequences |
| 502 | This function returns a list of all the elements in @var{sequence} | 577 | This function returns a list of all the elements in @var{sequence} |