Mercurial > hg > xemacs-beta
comparison man/lispref/sequences.texi @ 78:c7528f8e288d r20-0b34
Import from CVS: tag r20-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:05:42 +0200 |
parents | 131b0175ea99 |
children | 1ce6082ce73f |
comparison
equal
deleted
inserted
replaced
77:6cb4f478e7bc | 78:c7528f8e288d |
---|---|
300 @end itemize | 300 @end itemize |
301 | 301 |
302 @node Array Functions | 302 @node Array Functions |
303 @section Functions that Operate on Arrays | 303 @section Functions that Operate on Arrays |
304 | 304 |
305 In this section, we describe the functions that accept both strings | 305 In this section, we describe the functions that accept strings, vectors, |
306 and vectors. | 306 and bit vectors. |
307 | 307 |
308 @defun arrayp object | 308 @defun arrayp object |
309 This function returns @code{t} if @var{object} is an array (i.e., either a | 309 This function returns @code{t} if @var{object} is an array (i.e., a |
310 vector or a string). | 310 string, vector, or bit vector). |
311 | 311 |
312 @example | 312 @example |
313 @group | 313 @group |
314 (arrayp "asdf") | |
315 @result{} t | |
314 (arrayp [a]) | 316 (arrayp [a]) |
315 @result{} t | 317 @result{} t |
316 (arrayp "asdf") | 318 (arrayp #*101) |
317 @result{} t | 319 @result{} t |
318 @end group | 320 @end group |
319 @end example | 321 @end example |
320 @end defun | 322 @end defun |
321 | 323 |
334 @result{} 11 | 336 @result{} 11 |
335 @end group | 337 @end group |
336 | 338 |
337 @group | 339 @group |
338 (aref "abcdefg" 1) | 340 (aref "abcdefg" 1) |
339 @result{} 98 ; @r{@samp{b} is @sc{ASCII} code 98.} | 341 @result{} ?b |
342 @end group | |
343 | |
344 @group | |
345 (aref #*1101 2) | |
346 @result{} 0 | |
340 @end group | 347 @end group |
341 @end example | 348 @end example |
342 | 349 |
343 See also the function @code{elt}, in @ref{Sequence Functions}. | 350 See also the function @code{elt}, in @ref{Sequence Functions}. |
344 @end defun | 351 @end defun |
359 | 366 |
360 @group | 367 @group |
361 (setq x "asdfasfd") | 368 (setq x "asdfasfd") |
362 @result{} "asdfasfd" | 369 @result{} "asdfasfd" |
363 (aset x 3 ?Z) | 370 (aset x 3 ?Z) |
364 @result{} 90 | 371 @result{} ?Z |
365 x | 372 x |
366 @result{} "asdZasfd" | 373 @result{} "asdZasfd" |
374 @end group | |
375 | |
376 @group | |
377 (setq bv #*1111) | |
378 @result{} #*1111 | |
379 (aset bv 2 0) | |
380 @result{} 0 | |
381 bv | |
382 @result{} #*1101 | |
367 @end group | 383 @end group |
368 @end example | 384 @end example |
369 | 385 |
370 If @var{array} is a string and @var{object} is not a character, a | 386 If @var{array} is a string and @var{object} is not a character, a |
371 @code{wrong-type-argument} error results. | 387 @code{wrong-type-argument} error results. |
387 @group | 403 @group |
388 (setq s "When in the course") | 404 (setq s "When in the course") |
389 @result{} "When in the course" | 405 @result{} "When in the course" |
390 (fillarray s ?-) | 406 (fillarray s ?-) |
391 @result{} "------------------" | 407 @result{} "------------------" |
408 @end group | |
409 | |
410 @group | |
411 (setq bv #*1101) | |
412 @result{} #*1101 | |
413 (fillarray bv 0) | |
414 @result{} #*0000 | |
392 @end group | 415 @end group |
393 @end example | 416 @end example |
394 | 417 |
395 If @var{array} is a string and @var{object} is not a character, a | 418 If @var{array} is a string and @var{object} is not a character, a |
396 @code{wrong-type-argument} error results. | 419 @code{wrong-type-argument} error results. |
543 | 566 |
544 There is no limit on the size of a bit vector. You could, for example, | 567 There is no limit on the size of a bit vector. You could, for example, |
545 create a bit vector with 100,000 elements if you really wanted to. | 568 create a bit vector with 100,000 elements if you really wanted to. |
546 | 569 |
547 Bit vectors have a special printed representation consisting of | 570 Bit vectors have a special printed representation consisting of |
548 @samp{#*} followed by the bits of the vector. For example, a bit | 571 @samp{#*} followed by the bits of the vector. For example, a bit vector |
549 vector whose elements are 0, 1, 1, 0, and 1, respectively, is printed | 572 whose elements are 0, 1, 1, 0, and 1, respectively, is printed as |
550 as | |
551 | 573 |
552 @example | 574 @example |
553 #*01101 | 575 #*01101 |
554 @end example | 576 @end example |
555 | 577 |
568 @group | 590 @group |
569 (bit-vector-p #*01) | 591 (bit-vector-p #*01) |
570 @result{} t | 592 @result{} t |
571 (bit-vector-p [0 1]) | 593 (bit-vector-p [0 1]) |
572 @result{} nil | 594 @result{} nil |
573 (vectorp "asdf") | 595 (bit-vector-p "01") |
574 @result{} nil | 596 @result{} nil |
575 @end group | 597 @end group |
576 @end example | 598 @end example |
577 @end defun | 599 @end defun |
578 | 600 |
579 @defun bitp object | 601 @defun bitp object |
580 This function returns @code{t} if @var{object} is either 0 or 1. | 602 This function returns @code{t} if @var{object} is either 0 or 1. |
581 @end defun | 603 @end defun |
582 | 604 |
583 @defun bit-vector &rest objects | 605 @defun bit-vector &rest objects |
584 This function creates and returns a vector whose elements are the | 606 This function creates and returns a bit vector whose elements are the |
585 arguments, @var{objects}. The elements must be either of the two | 607 arguments @var{objects}. The elements must be either of the two |
586 integers 0 or 1. | 608 integers 0 or 1. |
587 | 609 |
588 @example | 610 @example |
589 @group | 611 @group |
590 (bit-vector 0 0 0 1 0 0 0 0 1 0) | 612 (bit-vector 0 0 0 1 0 0 0 0 1 0) |
591 @result{} #*0001000010 | 613 @result{} #*0001000010 |
592 (vector) | 614 (bit-vector) |
593 @result{} #* | 615 @result{} #* |
594 @end group | 616 @end group |
595 @end example | 617 @end example |
596 @end defun | 618 @end defun |
597 | 619 |
598 @defun make-bit-vector length object | 620 @defun make-bit-vector length object |
599 This function returns a new bit vector consisting of @var{length} elements, | 621 This function creates and returns a bit vector consisting of |
600 each initialized to @var{object}. | 622 @var{length} elements, each initialized to @var{object}. |
601 | 623 |
602 @example | 624 @example |
603 @group | 625 @group |
604 (setq sleepy (make-vector 9 1)) | 626 (setq picket-fence (make-bit-vector 9 1)) |
605 @result{} #*111111111 | 627 @result{} #*111111111 |
606 @end group | 628 @end group |
607 @end example | 629 @end example |
608 @end defun | 630 @end defun |
609 | 631 |
610 @defun bvconcat &rest sequences | 632 @defun bvconcat &rest sequences |
611 @cindex copying bit vectors | 633 @cindex copying bit vectors |
612 This function returns a new bit vector containing all the elements of the | 634 This function returns a new bit vector containing all the elements of |
613 @var{sequences}. The arguments @var{sequences} may be lists or vectors, | 635 the @var{sequences}. The arguments @var{sequences} may be lists, |
614 all of whose elements are the integers 0 or 1. If no @var{sequences} are | 636 vectors, or bit vectors, all of whose elements are the integers 0 or 1. |
615 given, an empty bit vector is returned. | 637 If no @var{sequences} are given, an empty bit vector is returned. |
616 | 638 |
617 The value is a newly constructed bit vector that is not @code{eq} to any | 639 The value is a newly constructed bit vector that is not @code{eq} to any |
618 existing vector. | 640 existing bit vector. |
619 | 641 |
620 @example | 642 @example |
621 @group | 643 @group |
622 (setq a (bvconcat '(1 1 0) '(0 0 1))) | 644 (setq a (bvconcat '(1 1 0) '(0 0 1))) |
623 @result{} #*110001 | 645 @result{} #*110001 |
640 The @code{append} function provides a way to convert a bit vector into a | 662 The @code{append} function provides a way to convert a bit vector into a |
641 list with the same elements (@pxref{Building Lists}): | 663 list with the same elements (@pxref{Building Lists}): |
642 | 664 |
643 @example | 665 @example |
644 @group | 666 @group |
645 (setq avector #*00001110) | 667 (setq bv #*00001110) |
646 @result{} #*00001110 | 668 @result{} #*00001110 |
647 (append avector nil) | 669 (append bv nil) |
648 @result{} (0 0 0 0 1 1 1 0) | 670 @result{} (0 0 0 0 1 1 1 0) |
649 @end group | 671 @end group |
650 @end example | 672 @end example |