Showing the changes to src/docs/array.sl (1 of 93 files). Show all
Unified · Split
| @@ -0,0 +1,63 @@ | ||
| 1 | + | |
| 2 | +(doc-group array | |
| 3 | + «Arrays and vectors.») | |
| 4 | + | |
| 5 | +(defdoc (copy-vec vec) | |
| 6 | + «Return a copy of the vector with the same elements. | |
| 7 | + | |
| 8 | + No copies of the values themselves are created, the original values | |
| 9 | + are reused.» | |
| 10 | + :doc-example | |
| 11 | + «(def v #vec(1 2 "three")) | |
| 12 | + (def q (copy-vec v)) | |
| 13 | + (eq? v q) | |
| 14 | + ; ↳ NIL | |
| 15 | + (equal? v q) | |
| 16 | + ; ↳ T | |
| 17 | + (map eq? v q) | |
| 18 | + ; ↳ #(T T T)» | |
| 19 | + :doc-group array) | |
| 20 | + | |
| 21 | +(defdoc (vec-alloc length . rest) | |
| 22 | + «Construct a vector of the specified `length` by repeating | |
| 23 | + the elements in `rest`.» | |
| 24 | + :doc-example | |
| 25 | + «(vec-alloc 5 2.5) | |
| 26 | + ; ↳ #(2.5 2.5 2.5 2.5 2.5)» | |
| 27 | + :doc-example | |
| 28 | + «(vec-alloc 10 1 2.5 "a" 'b) | |
| 29 | + ; ↳ #(1 2.5 "a" b 1 2.5 "a" b 1 2.5)» | |
| 30 | + :doc-group array | |
| 31 | + :doc-see vec | |
| 32 | + :doc-see arr-alloc) | |
| 33 | + | |
| 34 | +(defdoc (arr type . rest) | |
| 35 | + «Construct a packed array containing the specified arguments. | |
| 36 | + | |
| 37 | + The arguments will be coerced to a single `type` which must be | |
| 38 | + a fixed-width number or pointer type, or rune.» | |
| 39 | + :doc-example | |
| 40 | + «(arr 's8 0 1 2) | |
| 41 | + ; ↳ #arr(s8 0 1 2)» | |
| 42 | + :doc-example | |
| 43 | + «(arr 'rune 0 1 2) | |
| 44 | + ; ↳ #arr(rune #\nul #\soh #\stx)» | |
| 45 | + :doc-group array | |
| 46 | + :doc-see arr-alloc | |
| 47 | + :doc-see vec) | |
| 48 | + | |
| 49 | +(defdoc (arr-alloc type length . rest) | |
| 50 | + «Construct a packed array of the specified `length` by repeating | |
| 51 | + the elements in `rest`. | |
| 52 | + | |
| 53 | + The arguments will be coerced to a single `type` which must be | |
| 54 | + a fixed-width number or pointer type, or rune.» | |
| 55 | + :doc-example | |
| 56 | + «(arr-alloc 'u16 5 -1) | |
| 57 | + ; ↳ #arr(u16 65535 65535 65535 65535 65535)» | |
| 58 | + :doc-example | |
| 59 | + «(arr-alloc 's8 10 0 1 2) | |
| 60 | + ; ↳ #arr(s8 0 1 2 0 1 2 0 1 2 0)» | |
| 61 | + :doc-group array | |
| 62 | + :doc-see arr | |
| 63 | + :doc-see vec-alloc) | |