-
Notifications
You must be signed in to change notification settings - Fork 0
/
chap-15.texi
2622 lines (1815 loc) · 75.7 KB
/
chap-15.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@node Arrays
@chapter Arrays
@menu
* Array Concepts::
* Arrays Dictionary::
@end menu
@node Array Concepts
@section Array Concepts
@menu
* Array Elements::
* Specialized Arrays::
@end menu
@node Array Elements
@subsection Array Elements
An @term{array} contains a set of @term{objects} called @term{elements}
that can be referenced individually according to a rectilinear coordinate system.
@node Array Indices
@subsubsection Array Indices
An @term{array} @term{element} is referred to by a (possibly empty) series of indices.
The length of the series must equal the @term{rank} of the @term{array}.
Each index must be a non-negative @term{fixnum}
less than the corresponding @term{array} @term{dimension}.
@term{Array} indexing is zero-origin.
@node Array Dimensions
@subsubsection Array Dimensions
An axis of an @term{array} is called a @newterm{dimension}.
Each @term{dimension} is a non-negative
@term{fixnum};
if any dimension of an @term{array} is zero, the @term{array} has no elements.
It is permissible for a @term{dimension} to be zero,
in which case the @term{array} has no elements,
and any attempt to @term{access} an @term{element}
is an error. However, other properties of the @term{array},
such as the @term{dimensions} themselves, may be used.
@node Implementation Limits on Individual Array Dimensions
@subsubsection Implementation Limits on Individual Array Dimensions
An @term{implementation} may impose a limit on @term{dimensions} of an @term{array},
but there is a minimum requirement on that limit. See the @term{variable} @ref{array-dimension-limit}.
@node Array Rank
@subsubsection Array Rank
An @term{array} can have any number of @term{dimensions} (including zero).
The number of @term{dimensions} is called the @newterm{rank}.
If the rank of an @term{array} is zero then the @term{array} is said to have
no @term{dimensions}, and the product of the dimensions (see @symbolref{array-total-size, SYM})
is then 1; a zero-rank @term{array} therefore has a single element.
@node Vectors
@subsubsection Vectors
An @term{array} of @term{rank} one (@ie{} a one-dimensional @term{array})
is called a @newterm{vector}.
@node Fill Pointers
@subsubsection Fill Pointers
A @newterm{fill pointer} is a non-negative @term{integer} no
larger than the total number of @term{elements} in a @term{vector}.
Not all @term{vectors} have @term{fill pointers}.
See the @term{functions} @ref{make-array} and @symbolref{adjust-array, SYM}.
An @term{element} of a @term{vector} is said to be @newterm{active} if it has
an index that is greater than or equal to zero,
but less than the @term{fill pointer} (if any).
For an @term{array} that has no @term{fill pointer},
all @term{elements} are considered @term{active}.
Only @term{vectors} may have @term{fill pointers};
multidimensional @term{arrays} may not.
A multidimensional @term{array} that is displaced to a @term{vector}
that has a @term{fill pointer} can be created.
@node Multidimensional Arrays
@subsubsection Multidimensional Arrays
@node Storage Layout for Multidimensional Arrays
@subsubsection Storage Layout for Multidimensional Arrays
Multidimensional @term{arrays} store their components in row-major order;
that is, internally a multidimensional @term{array} is stored as a
one-dimensional @term{array}, with the multidimensional index sets
ordered lexicographically, last index varying fastest.
@node Implementation Limits on Array Rank
@subsubsection Implementation Limits on Array Rank
An @term{implementation} may impose a limit on the @term{rank} of an @term{array},
but there is a minimum requirement on that limit. See the @term{variable} @ref{array-rank-limit}.
@node Specialized Arrays
@subsection Specialized Arrays
An @term{array} can be a @term{general} @term{array},
meaning each @term{element} may be any @term{object},
or it may be a @term{specialized} @term{array},
meaning that each @term{element} must be of a restricted @term{type}.
The phrasing ``an @term{array} @term{specialized} to @term{type} @metavar{type}''
is sometimes used to emphasize the @term{element type} of an @term{array}.
This phrasing is tolerated even when the @metavar{type} is @symbolref{t, SC},
even though an @term{array} @term{specialized} to @term{type} @term{t}
is a @term{general} @term{array}, not a @term{specialized} @term{array}.
@Thenextfigure{}@spc{}lists some @term{defined names} that are applicable to @term{array}
creation, @term{access}, and information operations.
@float Figure,fig15.1
@cartouche
@multitable{array-dimension-limit}{array-has-fill-pointer-p}{upgraded-array-element-type}
@item adjust-array @tab array-has-fill-pointer-p @tab make-array
@item adjustable-array-p @tab array-in-bounds-p @tab svref
@item aref @tab array-rank @tab upgraded-array-element-type
@item array-dimension @tab array-rank-limit @tab upgraded-complex-part-type
@item array-dimension-limit @tab array-row-major-index @tab vector
@item array-dimensions @tab array-total-size @tab vector-pop
@item array-displacement @tab array-total-size-limit @tab vector-push
@item array-element-type @tab fill-pointer @tab vector-push-extend
@end multitable
@end cartouche
@caption{General Purpose Array-Related Defined Names}
@end float
@node Array Upgrading
@subsubsection Array Upgrading
The @newterm{upgraded array element type} of a @term{type} @mat{T@sub{1}}
is a @term{type} @mat{T@sub{2}} that is a @term{supertype} of @mat{T@sub{1}}
and that is used instead of @mat{T@sub{1}} whenever @mat{T@sub{1}}
is used as an @term{array element type}
for object creation or type discrimination.
During creation of an @term{array},
the @term{element type} that was requested
is called the @newterm{expressed array element type}.
The @term{upgraded array element type} of the @term{expressed array element type}
becomes the @newterm{actual array element type} of the @term{array} that is created.
@term{Type} @term{upgrading} implies a movement upwards in the type hierarchy lattice.
A @term{type} is always a @term{subtype} of its @term{upgraded array element type}.
Also, if a @term{type} @mat{T@sub{x}} is a @term{subtype} of another @term{type} @mat{T@sub{y}},
then
the @term{upgraded array element type} of @mat{T@sub{x}}
must be a @term{subtype} of
the @term{upgraded array element type} of @mat{T@sub{y}}.
Two @term{disjoint} @term{types} can be @term{upgraded} to the same @term{type}.
The @term{upgraded array element type} @mat{T@sub{2}} of a @term{type} @mat{T@sub{1}}
is a function only of @mat{T@sub{1}} itself;
that is, it is independent of any other property of the @term{array}
for which @mat{T@sub{2}} will be used,
such as @term{rank}, @term{adjustability}, @term{fill pointers}, or displacement.
@Thefunction{upgraded-array-element-type}
can be used by @term{conforming programs} to predict how the @term{implementation}
will @term{upgrade} a given @term{type}.
@node Required Kinds of Specialized Arrays
@subsubsection Required Kinds of Specialized Arrays
@term{Vectors} whose @term{elements} are restricted to @term{type}
@symbolref{character, SC} or a @term{subtype} of @symbolref{character, SC}
are called
@cindex string
@dfn{strings}.
@term{Strings} are @oftype{string}.
@Thenextfigure{}@spc{}lists some @term{defined names} related to @term{strings}.
@term{Strings} are @term{specialized} @term{arrays}
and might logically have been included in this chapter.
However, for purposes of readability
most information about @term{strings} does not appear in this chapter;
see instead @ref{Strings, Chapter 16 (Strings)}.
@float Figure,fig15.2
@cartouche
@multitable{nstring-capitalize}{string-not-greaterp}{string@tt{/=}}
@item char @tab string-equal @tab string-upcase
@item make-string @tab string-greaterp @tab string@tt{/=}
@item nstring-capitalize @tab string-left-trim @tab string@tt{<}
@item nstring-downcase @tab string-lessp @tab string@tt{<=}
@item nstring-upcase @tab string-not-equal @tab string@tt{=}
@item schar @tab string-not-greaterp @tab string@tt{>}
@item string @tab string-not-lessp @tab string@tt{>=}
@item string-capitalize @tab string-right-trim @tab
@item string-downcase @tab string-trim @tab
@end multitable
@end cartouche
@caption{Operators that Manipulate Strings}
@end float
@term{Vectors} whose @term{elements} are restricted to @term{type}
@symbolref{bit, T} are called
@cindex bit vector
@dfn{bit vectors}.
@term{Bit vectors} are @oftype{bit-vector}.
@Thenextfigure{}@spc{}lists some @term{defined names} for operations on @term{bit arrays}.
@float Figure,fig15.3
@cartouche
@multitable{bit-andc1}{bit-nand}{bit-orc2}
@item bit @tab bit-ior @tab bit-orc2
@item bit-and @tab bit-nand @tab bit-xor
@item bit-andc1 @tab bit-nor @tab sbit
@item bit-andc2 @tab bit-not @tab
@item bit-eqv @tab bit-orc1 @tab
@end multitable
@end cartouche
@caption{Operators that Manipulate Bit Arrays}
@end float
@node Arrays Dictionary
@section Arrays Dictionary
@menu
* array::
* simple-array::
* vector (System Class)::
* simple-vector::
* bit-vector::
* simple-bit-vector::
* make-array::
* adjust-array::
* adjustable-array-p::
* aref::
* array-dimension::
* array-dimensions::
* array-element-type::
* array-has-fill-pointer-p::
* array-displacement::
* array-in-bounds-p::
* array-rank::
* array-row-major-index::
* array-total-size::
* arrayp::
* fill-pointer::
* row-major-aref::
* upgraded-array-element-type::
* array-dimension-limit::
* array-rank-limit::
* array-total-size-limit::
* simple-vector-p::
* svref::
* vector (Function)::
* vector-pop::
* vector-push; vector-push-extend::
* vectorp::
* bit; sbit::
* bit-and; bit-andc1; bit-andc2; bit-eqv; bit-ior; bit-nand; bit-nor; bit+::
* bit-vector-p::
* simple-bit-vector-p::
@end menu
@node array
@syindexanchor{array, SYM}
@subsection array (System Class)
@cindex array
@subsubheading Class Precedence List:
@symbolref{array, SYM},
@symbolref{t, SC}
@subsubheading Description:
An @term{array} contains @term{objects} arranged according to a
Cartesian coordinate system.
An @term{array} provides mappings from a set of
@term{fixnums}
@mat{@left{}@lcurly{}i@sub{0},i@sub{1},@dots{},i@sub{r-1}@right{}@rcurly{}} to corresponding @term{elements}
of the @term{array},
where @mat{0 @le{} i@sub{j} < d@sub{j}},
@mat{r} is the rank of the array, and @mat{d@sub{j}} is the size of @term{dimension} @mat{j} of
the array.
When an @term{array} is created, the program requesting its creation may
declare that all @term{elements} are of a particular @term{type},
called the @term{expressed array element type}.
The implementation is permitted to @term{upgrade} this type in order to
produce the @term{actual array element type},
which is the @term{element type} for the @term{array} is actually @term{specialized}.
See the @term{function} @ref{upgraded-array-element-type}.
@subsubheading Compound Type Specifier Kind:
Specializing.
@subsubheading Compound Type Specifier Syntax:
@Deftype{array, @ttbrac{@curly{element-type | @t{*}} @brac{dimension-spec}}}
@auxbnf{dimension-spec, rank | @t{*} | @paren{@star{@curly{dimension | @t{*}}}}}
@subsubheading Compound Type Specifier Arguments:
@param{dimension}---a @term{valid array dimension}.
@param{element-type}---a @term{type specifier}.
@param{rank}---a non-negative @term{fixnum}.
@subsubheading Compound Type Specifier Description:
This denotes the set of @term{arrays} whose
@term{element type}, @term{rank}, and @term{dimensions}
match any given
@param{element-type}, @param{rank}, and @param{dimensions}.
Specifically:
If @param{element-type} is the @term{symbol} @t{*},
@term{arrays} are not excluded on the basis of their @term{element type}.
Otherwise, only those @param{arrays} are included whose @term{actual array element type}
is the result of @term{upgrading} @param{element-type};
see @ref{Array Upgrading}.
If the @param{dimension-spec} is a @param{rank},
the set includes only those @param{arrays} having that @term{rank}.
If the @param{dimension-spec} is a @term{list} of @param{dimensions},
the set includes only those @param{arrays} having a @term{rank}
given by the @term{length} of the @param{dimensions},
and having the indicated @param{dimensions};
in this case, @t{*} matches any value for the corresponding @term{dimension}.
If the @param{dimension-spec} is the @term{symbol} @t{*},
the set is not restricted on the basis of @term{rank} or @term{dimension}.
@subsubheading See Also:
@ref{*print-array*},
@ref{aref},
@ref{make-array},
@ref{vector (System Class)},
@ref{Sharpsign A},
@ref{Printing Other Arrays}
@subsubheading Notes:
Note that the type @tt{(array t)}
is a proper @term{subtype} of the type @tt{(array *)}.
The reason is that the type @tt{(array t)} is the set of @term{arrays}
that can
hold any @term{object} (the @term{elements} are @oftype{t}, which includes
all @term{objects}).
On the other hand, the type @tt{(array *)}
is the set of all @term{arrays} whatsoever, including for example
@term{arrays} that can hold only @term{characters}.
The type @tt{(array character)}
is not a @term{subtype} of the type @tt{(array t)};
the two sets
are @term{disjoint} because the type @tt{(array character)} is not the
set of all @term{arrays} that can hold
@term{characters}, but rather the set of
@term{arrays}
that are specialized to hold precisely @term{characters} and no
other @term{objects}.
@node simple-array
@syindexanchor{simple-array, SYM}
@subsection simple-array (Type)
@cindex simple-array
@subsubheading Supertypes:
@symbolref{simple-array, SYM},
@symbolref{array, SYM},
@symbolref{t, SC}
@subsubheading Description:
The @term{type} of an @term{array} that is not displaced
to another @term{array}, has no @term{fill pointer}, and is
not
@term{expressly adjustable} is a @subtypeof{simple-array}.
The concept of a @term{simple array}
exists to allow the implementation to use a specialized representation
and to allow the user to declare that certain values will always be
@term{simple arrays}.
The @term{types} @symbolref{simple-vector, SYM},
@symbolref{simple-string, SYM},
and @symbolref{simple-bit-vector, SYM}
are @term{disjoint} @subtypesof{simple-array},
for they respectively mean @f{(simple-array t (*))},
the union of all @f{(simple-array @i{c} (*))}
for any @i{c} being a @subtypeof{character},
and @f{(simple-array bit (*))}.
@subsubheading Compound Type Specifier Kind:
Specializing.
@subsubheading Compound Type Specifier Syntax:
@Deftype{simple-array, @ttbrac{@curly{element-type | @t{*}} @brac{dimension-spec}}}
@auxbnf{dimension-spec, rank | @t{*} | @paren{@star{@curly{dimension | @t{*}}}}}
@subsubheading Compound Type Specifier Arguments:
@param{dimension}---a @term{valid array dimension}.
@param{element-type}---a @term{type specifier}.
@param{rank}---a non-negative @term{fixnum}.
@subsubheading Compound Type Specifier Description:
This @term{compound type specifier} is treated exactly as the corresponding
@term{compound type specifier} for @term{type} @symbolref{array, SYM} would be treated,
except that the set is further constrained to include only @term{simple arrays}.
@subsubheading Notes:
It is @term{implementation-dependent}
whether @term{displaced arrays},
@term{vectors} with @term{fill pointers},
or arrays that are @term{actually adjustable}
are @term{simple arrays}.
@tt{(simple-array *)} refers to all @term{simple arrays}
regardless of element type, @tt{(simple-array @param{type-specifier})}
refers only to those @term{simple arrays}
that can result from giving @param{type-specifier} as the
@kwd{element-type} argument to @symbolref{make-array, SYM}.
@node vector (System Class)
@syindexanchor{vector, SC}
@subsection vector (System Class)
@cindex vector
@subsubheading Class Precedence List:
@symbolref{vector, SC},
@symbolref{array, SYM},
@symbolref{sequence, SYM},
@symbolref{t, SC}
@subsubheading Description:
Any one-dimensional @term{array} is a @term{vector}.
@Thetype{vector} is a @subtypeof{array};
for all @term{types} @f{x}, @tt{(vector x)} is the same as @tt{(array x (*))}.
The @term{type} @tt{(vector t)}, @thetype{string}, and @thetype{bit-vector}
are @term{disjoint} @subtypesof{vector}.
@subsubheading Compound Type Specifier Kind:
Specializing.
@subsubheading Compound Type Specifier Syntax:
@Deftype{vector, @ttbrac{@curly{element-type | @t{*}} @brac{@curly{size | @t{*}}}}}
@subsubheading Compound Type Specifier Arguments:
@param{size}---a non-negative @term{fixnum}.
@param{element-type}---a @term{type specifier}.
@subsubheading Compound Type Specifier Description:
This denotes the set of specialized @term{vectors}
whose @term{element type} and @param{dimension} match the specified values.
Specifically:
If @param{element-type} is the @term{symbol} @t{*},
@term{vectors} are not excluded on the basis of their @term{element type}.
Otherwise, only those @param{vectors} are included whose @term{actual array element type}
is the result of @term{upgrading} @param{element-type};
see @ref{Array Upgrading}.
If a @param{size} is specified,
the set includes only those @param{vectors} whose only @term{dimension}
is @param{size}.
If the @term{symbol} @t{*} is specified instead of a @param{size},
the set is not restricted on the basis of @term{dimension}.
@subsubheading See Also:
@ref{Required Kinds of Specialized Arrays},
@ref{Sharpsign Left-Parenthesis},
@ref{Printing Other Vectors},
@ref{Sharpsign A}
@subsubheading Notes:
The @term{type} @f{(vector @param{e} @param{s})}
is equivalent to the @term{type} @f{(array @param{e} (@param{s}))}.
The type @f{(vector bit)} has the name @symbolref{bit-vector, SYM}.
The union of all @term{types} @f{(vector @mat{C})},
where @mat{C} is any @term{subtype} of @symbolref{character, SC},
has the name @symbolref{string, SC}.
@tt{(vector *)} refers to all @term{vectors}
regardless of element type, @tt{(vector @param{type-specifier})}
refers only to those @term{vectors}
that can result from giving @param{type-specifier} as the
@kwd{element-type} argument to @symbolref{make-array, SYM}.
@node simple-vector
@syindexanchor{simple-vector, SYM}
@subsection simple-vector (Type)
@cindex simple-vector
@subsubheading Supertypes:
@symbolref{simple-vector, SYM},
@symbolref{vector, SC},
@symbolref{simple-array, SYM},
@symbolref{array, SYM},
@symbolref{sequence, SYM},
@symbolref{t, SC}
@subsubheading Description:
The @term{type} of a @term{vector} that is not displaced to another
@term{array}, has no @term{fill pointer}, is not
@term{expressly adjustable}
and is able to hold
elements of any @term{type} is a @subtypeof{simple-vector}.
@Thetype{simple-vector} is a @subtypeof{vector},
and is a @term{subtype} of @term{type} @f{(vector t)}.
@subsubheading Compound Type Specifier Kind:
Specializing.
@subsubheading Compound Type Specifier Syntax:
@Deftype{simple-vector, @ttbrac{size}}
@subsubheading Compound Type Specifier Arguments:
@param{size}---a non-negative @term{fixnum},
or the @term{symbol} @t{*}.
@Default{the @term{symbol} @t{*}}
@subsubheading Compound Type Specifier Description:
This is the same as @tt{(simple-array t (@param{size}))}.
@node bit-vector
@syindexanchor{bit-vector, SYM}
@subsection bit-vector (System Class)
@cindex bit-vector
@subsubheading Class Precedence List:
@symbolref{bit-vector, SYM},
@symbolref{vector, SC},
@symbolref{array, SYM},
@symbolref{sequence, SYM},
@symbolref{t, SC}
@subsubheading Description:
A @term{bit vector} is a @term{vector} the @term{element type} of which is @term{bit}.
@Thetype{bit-vector} is a @subtypeof{vector},
for @symbolref{bit-vector, SYM} means @f{(vector bit)}.
@subsubheading Compound Type Specifier Kind:
Abbreviating.
@subsubheading Compound Type Specifier Syntax:
@Deftype{bit-vector, @ttbrac{size}}
@subsubheading Compound Type Specifier Arguments:
@param{size}---a non-negative @term{fixnum},
or the @term{symbol} @t{*}.
@subsubheading Compound Type Specifier Description:
This denotes the same @term{type} as the @term{type} @tt{(array bit (@param{size}))};
that is, the set of @term{bit vectors} of size @param{size}.
@subsubheading See Also:
@ref{Sharpsign Asterisk},
@ref{Printing Bit Vectors},
@ref{Required Kinds of Specialized Arrays}
@node simple-bit-vector
@syindexanchor{simple-bit-vector, SYM}
@subsection simple-bit-vector (Type)
@cindex simple-bit-vector
@subsubheading Supertypes:
@symbolref{simple-bit-vector, SYM},
@symbolref{bit-vector, SYM},
@symbolref{vector, SC},
@symbolref{simple-array, SYM},
@symbolref{array, SYM},
@symbolref{sequence, SYM},
@symbolref{t, SC}
@subsubheading Description:
The @term{type} of a @term{bit vector} that is not displaced
to another @term{array}, has no @term{fill pointer}, and is
not
@term{expressly adjustable}
is a
@subtypeof{simple-bit-vector}.
@subsubheading Compound Type Specifier Kind:
Abbreviating.
@subsubheading Compound Type Specifier Syntax:
@Deftype{simple-bit-vector, @ttbrac{size}}
@subsubheading Compound Type Specifier Arguments:
@param{size}---a non-negative @term{fixnum},
or the @term{symbol} @t{*}.
@Default{the @term{symbol} @t{*}}
@subsubheading Compound Type Specifier Description:
This denotes the same type as the @term{type}
@f{(simple-array bit (@param{size}))};
that is, the set of @term{simple bit vectors} of size @param{size}.
@node make-array
@syindexanchor{make-array, SYM}
@subsection make-array (Function)
@cindex make-array
@subsubheading Syntax:
@DefunWithValuesNewline{make-array, dimensions @keyparam{} @vtop{@hbox{element-type} @hbox{initial-element} @hbox{initial-contents} @hbox{adjustable} @hbox{fill-pointer} @hbox{displaced-to} @hbox{displaced-index-offset}}, new-array}
@subsubheading Arguments and Values:
@param{dimensions}---a @term{designator} for a @term{list} of @term{valid array dimensions}.
@param{element-type}---a @term{type specifier}.
@Default{@symbolref{t, SC}}
@param{initial-element}---an @term{object}.
@param{initial-contents}---an @term{object}.
@param{adjustable}---a @term{generalized boolean}.
@Default{@nil{}}
@param{fill-pointer}---a @term{valid fill pointer} for the @term{array} to be created,
or @symbolref{t, SC}@spc{}or @nil{}.
@Default{@nil{}}
@param{displaced-to}---an @term{array} or @nil{}.
@Default{@nil{}}
This option must not be supplied if either @param{initial-element}
or @param{initial-contents} is supplied.
@param{displaced-index-offset}---a @term{valid array row-major index}
for @param{displaced-to}. @Default{@f{0}}
This option must not be supplied unless a @term{non-nil} @param{displaced-to} is supplied.
@param{new-array}---an @term{array}.
@subsubheading Description:
Creates and returns an @term{array} constructed of the most @term{specialized}
@term{type} that can accommodate elements of @term{type} given by @param{element-type}.
If @param{dimensions} is @nil{}@spc{}then a zero-dimensional @term{array} is created.
@param{Dimensions} represents the dimensionality of the new @term{array}.
@param{element-type} indicates the @term{type} of the elements intended to be stored
in the @param{new-array}. The @param{new-array} can actually store any @term{objects}
of the @term{type} which results from @term{upgrading} @param{element-type};
see @ref{Array Upgrading}.
If @param{initial-element} is supplied,
it is used to initialize each @term{element} of @param{new-array}.
If @param{initial-element} is supplied,
it must be of the @term{type} given by @param{element-type}.
@param{initial-element} cannot be supplied if either the @kwd{initial-contents} option
is supplied or @param{displaced-to} is @term{non-nil}.
If @param{initial-element} is not supplied,
the consequences of later reading an uninitialized @term{element} of @param{new-array}
are undefined
unless either @param{initial-contents} is supplied
or @param{displaced-to} is @term{non-nil}.
@param{initial-contents} is used to initialize the contents of @term{array}.
For example:
@lisp
(make-array '(4 2 3) :initial-contents
'(((a b c) (1 2 3))
((d e f) (3 1 2))
((g h i) (2 3 1))
((j k l) (0 0 0))))
@end lisp
@param{initial-contents} is composed of a nested structure of @term{sequences}.
The numbers of levels in the structure must equal the rank of @term{array}.
Each leaf of the nested structure must be of the @term{type} given by @param{element-type}.
If @term{array} is zero-dimensional, then @param{initial-contents} specifies the single
@term{element}. Otherwise, @param{initial-contents} must be a @term{sequence}
whose length is equal to the first dimension; each element must be a nested
structure for an @term{array} whose dimensions are the remaining dimensions,
and so on.
@param{Initial-contents} cannot be supplied if either
@param{initial-element} is supplied
or @param{displaced-to} is @term{non-nil}.
If @param{initial-contents} is not supplied,
the consequences of later reading an uninitialized @term{element} of @param{new-array}
are undefined
unless either @param{initial-element} is supplied
or @param{displaced-to} is @term{non-nil}.
If @param{adjustable} is @term{non-nil},
the array is @term{expressly adjustable}
(and so @term{actually adjustable});
otherwise, the array is not @term{expressly adjustable}
(and it is @term{implementation-dependent} whether
the array is @term{actually adjustable}).
If @param{fill-pointer} is @term{non-nil},
the @term{array} must be one-dimensional;
that is, the @term{array} must be a @term{vector}.
If @param{fill-pointer} is @symbolref{t, SC},
the length of the @term{vector} is used to initialize the @term{fill pointer}.
If @param{fill-pointer} is an @term{integer},
it becomes the initial @term{fill pointer} for the @term{vector}.
If @param{displaced-to} is @term{non-nil},
@symbolref{make-array, SYM} will create a @term{displaced array}
and @param{displaced-to} is the @term{target} of that @term{displaced array}.
In that case, the consequences are undefined if the @term{actual array element type} of
@param{displaced-to} is not @term{type equivalent} to the @term{actual array element type}
of the @term{array} being created.
If @param{displaced-to} is @nil{}, the @term{array} is not a @term{displaced array}.
The @param{displaced-index-offset} is made to be the index offset of the @term{array}.
When an array A is given as
@thekeyarg{displaced-to} to @symbolref{make-array, SYM}
when creating array B,
then array B is said to be displaced to array A. The
total number of elements in an @term{array},
called the total size of the @term{array},
is calculated as the product of all the dimensions.
It is required that the total size of A be no smaller than the sum
of the total size of B plus the offset @f{n} supplied by
the @param{displaced-index-offset}.
The effect of displacing is that array B does not have any
elements of its own, but instead maps @term{accesses} to itself into
@term{accesses} to array A. The mapping treats both @term{arrays} as if they
were one-dimensional by taking the elements in row-major order,
and then maps an @term{access} to element @f{k} of array B to an @term{access} to element
@f{k}+@f{n} of array A.
If @symbolref{make-array, SYM} is called with @param{adjustable}, @param{fill-pointer},
and @param{displaced-to} each @nil{},
then the result is a @term{simple array}.
If @symbolref{make-array, SYM} is called with one or more of @param{adjustable},
@param{fill-pointer}, or @param{displaced-to} being @term{true}, whether the
resulting @term{array} is a @term{simple array} is @term{implementation-dependent}.
When an array A is given as @thekeyarg{displaced-to} to
@symbolref{make-array, SYM} when creating array B, then array B is said to
be displaced to array A. The total number of elements in an @term{array},
called the total size of the @term{array}, is calculated as the product
of all the dimensions.
The consequences are unspecified if
the total size of A is smaller than the sum
of the total size of B plus the offset @f{n} supplied by
the @param{displaced-index-offset}.
The effect of displacing is that array B does not have any
elements of its own, but instead maps @term{accesses} to itself into
@term{accesses} to array A. The mapping treats both @term{arrays} as if they
were one-dimensional by taking the elements in row-major order,
and then maps an @term{access} to element @f{k} of array B to an @term{access}
to @term{element} @f{k}+@f{n} of array A.
@subsubheading Examples:
@lisp
(make-array 5) ;; Creates a one-dimensional array of five elements.
(make-array '(3 4) :element-type '(mod 16)) ;; Creates a
;;two-dimensional array, 3 by 4, with four-bit elements.
(make-array 5 :element-type 'single-float) ;; Creates an array of single-floats.
@end lisp
@lisp
(make-array nil :initial-element nil) @EV{} #0ANIL
(make-array 4 :initial-element nil) @EV{} #(NIL NIL NIL NIL)
(make-array '(2 4)
:element-type '(unsigned-byte 2)
:initial-contents '((0 1 2 3) (3 2 1 0)))
@EV{} #2A((0 1 2 3) (3 2 1 0))
(make-array 6
:element-type 'character
:initial-element #@bsl{}a
:fill-pointer 3) @EV{} "aaa"
@end lisp
The following is an example of making a @term{displaced array}.
@lisp
(setq a (make-array '(4 3)))
@EV{} #<ARRAY 4x3 simple 32546632>
(dotimes (i 4)
(dotimes (j 3)
(setf (aref a i j) (list i 'x j '= (* i j)))))
@EV{} NIL
(setq b (make-array 8 :displaced-to a
:displaced-index-offset 2))
@EV{} #<ARRAY 8 indirect 32550757>
(dotimes (i 8)
(print (list i (aref b i))))
@OUT{} (0 (0 X 2 = 0))
@OUT{} (1 (1 X 0 = 0))
@OUT{} (2 (1 X 1 = 1))
@OUT{} (3 (1 X 2 = 2))
@OUT{} (4 (2 X 0 = 0))
@OUT{} (5 (2 X 1 = 2))
@OUT{} (6 (2 X 2 = 4))
@OUT{} (7 (3 X 0 = 0))
@EV{} NIL
@end lisp
The last example depends on the fact that @term{arrays} are, in effect,
stored in row-major order.
@lisp
(setq a1 (make-array 50))
@EV{} #<ARRAY 50 simple 32562043>
(setq b1 (make-array 20 :displaced-to a1 :displaced-index-offset 10))
@EV{} #<ARRAY 20 indirect 32563346>
(length b1) @EV{} 20
(setq a2 (make-array 50 :fill-pointer 10))
@EV{} #<ARRAY 50 fill-pointer 10 46100216>
(setq b2 (make-array 20 :displaced-to a2 :displaced-index-offset 10))
@EV{} #<ARRAY 20 indirect 46104010>
(length a2) @EV{} 10
(length b2) @EV{} 20
(setq a3 (make-array 50 :fill-pointer 10))
@EV{} #<ARRAY 50 fill-pointer 10 46105663>
(setq b3 (make-array 20 :displaced-to a3 :displaced-index-offset 10
:fill-pointer 5))
@EV{} #<ARRAY 20 indirect, fill-pointer 5 46107432>
(length a3) @EV{} 10
(length b3) @EV{} 5
@end lisp
@subsubheading See Also:
@ref{adjustable-array-p},
@ref{aref},
@ref{arrayp},
@ref{array-element-type},
@ref{array-rank-limit},
@ref{array-dimension-limit},
@ref{fill-pointer},
@ref{upgraded-array-element-type}
@subsubheading Notes:
There is no specified way to create an @term{array}
for which @symbolref{adjustable-array-p, SYM} definitely
returns @term{false}.
There is no specified way to create an @term{array}
that is not a @term{simple array}.
@node adjust-array
@syindexanchor{adjust-array, SYM}
@subsection adjust-array (Function)
@cindex adjust-array
@subsubheading Syntax:
@DefunWithValuesNewline{adjust-array, array new-dimensions @keyparam{} @vtop{@hbox{element-type} @hbox{initial-element} @hbox{initial-contents} @hbox{fill-pointer} @hbox{displaced-to} @hbox{displaced-index-offset}}, adjusted-array}
@subsubheading Arguments and Values:
@param{array}---an @term{array}.
@param{new-dimensions}---a @term{valid array dimension}
or a @term{list} of @term{valid array dimensions}.
@param{element-type}---a @term{type specifier}.
@param{initial-element}---an @term{object}.
@param{Initial-element} must not be supplied if either
@param{initial-contents} or @param{displaced-to} is supplied.
@param{initial-contents}---an @term{object}.
If @term{array} has rank greater than zero, then @param{initial-contents}
is composed of nested @term{sequences}, the depth of which must equal
the rank of @param{array}. Otherwise, @term{array} is zero-dimensional and
@param{initial-contents} supplies the single element.
@param{initial-contents} must not be supplied if either
@param{initial-element} or @param{displaced-to} is given.
@param{fill-pointer}---a @term{valid fill pointer} for the
@term{array} to be created, or @symbolref{t, SC}, or @nil{}.
@Default{@nil{}}
@param{displaced-to}---an @term{array} or @nil{}.
@param{initial-elements} and @param{initial-contents} must not be supplied
if @param{displaced-to} is supplied.
@param{displaced-index-offset}---an @objectoftype{(fixnum 0 @i{n})}
where @i{n} is @tt{(array-total-size @param{displaced-to})}.
@param{displaced-index-offset} may be supplied only if @param{displaced-to} is supplied.
@param{adjusted-array}---an @term{array}.
@subsubheading Description:
@symbolref{adjust-array, SYM} changes the dimensions or elements of @param{array}.
The result is an @term{array} of the same @term{type} and rank as @param{array},
that is either the modified @param{array},
or a newly created @term{array} to which
@param{array} can be displaced, and that has
the given @param{new-dimensions}.
@param{New-dimensions} specify the size of each @term{dimension} of @param{array}.
@param{Element-type} specifies the @term{type} of the @term{elements}
of the resulting @term{array}. If @param{element-type} is supplied,
the consequences are unspecified if
the @term{upgraded array element type} of @param{element-type}
is not the same as the @term{actual array element type} of @param{array}.
If @param{initial-contents} is supplied, it is treated as for
@symbolref{make-array, SYM}. In this case none of the original contents of
@param{array} appears in the resulting @term{array}.
If @param{fill-pointer} is an @term{integer},
it becomes the @term{fill pointer} for the resulting @term{array}.
If @param{fill-pointer} is the symbol @symbolref{t, SC},
it indicates that the size of the resulting @term{array}
should be used as the @term{fill pointer}.