comparison man/lispref/sequences.texi @ 70:131b0175ea99 r20-0b30

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