(sigil array)
(sigil array) - Array Utilities
Higher-order functions for working with Sigil's dynamic arrays. For basic array operations (array, array-ref, array-set!, array-length, array-push, array-slice), use the prelude.
(import (sigil array))
(array-map (lambda (x) (* x 2)) #[1 2 3]) ; => #[2 4 6]
(array-filter odd? #[1 2 3 4 5]) ; => #[1 3 5]
(array-fold + 0 #[1 2 3 4 5]) ; => 15Exports
make-arrayprocedureCreate an array of the given size, optionally filled with a value.
(make-array 5) ; => #[#f #f #f #f #f]
(make-array 3 0) ; => #[0 0 0]
(make-array 4 'x) ; => #[x x x x]array-copyprocedureCreate a copy of an array.
(define a #[1 2 3])
(define b (array-copy a))
(array-set! b 0 99)
a ; => #[1 2 3] (unchanged)
b ; => #[99 2 3]array-mapprocedureApply a function to each element of an array, returning a new array.
(array-map (lambda (x) (* x 2)) #[1 2 3])
; => #[2 4 6]array-for-eachprocedureApply a procedure to each element of an array for side effects.
(array-for-each display #[1 2 3])
; prints: 123array-foldprocedureFold a function over an array from left to right.
(array-fold + 0 #[1 2 3 4 5])
; => 15array-filterprocedureReturn a new array containing only elements that satisfy the predicate.
(array-filter odd? #[1 2 3 4 5])
; => #[1 3 5]array-findprocedureFind the first element satisfying the predicate, or #f if none.
(array-find even? #[1 3 4 5])
; => 4array-indexprocedureFind the index of the first element satisfying the predicate, or #f.
(array-index even? #[1 3 4 5])
; => 2array-every?procedureCheck if all elements satisfy the predicate.
(array-every? positive? #[1 2 3])
; => #tarray-any?procedureCheck if any element satisfies the predicate.
(array-any? even? #[1 3 4 5])
; => #t