6.1 Quick Start
> (array #[0 1 2 3 4]) - : (Array Byte)
(array #[0 1 2 3 4])
> (array #[#['first 'row 'data] #['second 'row 'data]]) - : (Array (U 'first 'row 'data 'second))
(array #[#['first 'row 'data] #['second 'row 'data]])
> (array "This array has zero axes and one element") - : (Array String)
(array "This array has zero axes and one element")
> (define arr (build-array #(4 5) (λ: ([js : Indexes]) (match-define (vector j0 j1) js) (+ j0 j1))))
> arr eval:9:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr1
in: arr
> (array-ref arr #(2 3)) eval:10:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr1
in: #(2 3)
> (define brr (array->mutable-array arr)) eval:11:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr1
in: arr
> (array-set! brr #(2 3) -1000) eval:12:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: brr
in: -1000
> brr eval:13:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: brr
in: brr
> (array-map (λ: ([n : Natural]) (* 2 n)) arr) eval:14:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr1
in: arr
> (array+ arr arr)
eval:15:0: Type Checker: missing type for top-level identifier;
either undefined or missing a type annotation
identifier: arr1
in: arr
context...:
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form
fail-to-succeed
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4
/Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop
eval:15:0: Type Checker: missing type for top-level identifier;
either undefined or missing a type annotation
identifier: arr1
in: arr
context...:
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/utils/tc-utils.rkt:123:0: report-all-errors
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:515:0: tc-toplevel-form
fail-to-succeed
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:39:0: tc-setup
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:24:4
/Users/mflatt/build/macro/racket/collects/racket/private/more-scheme.rkt:148:2: call-with-break-parameterization
/Users/mflatt/build/macro/build/user/6.2.900.4/pkgs/sandbox-lib/racket/sandbox.rkt:837:5: loop
Type Checker: Summary: 2 errors encountered
> (array* arr (array 2)) eval:16:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr1
in: 2
> (array* arr (array #[0 2 0 2 0])) eval:17:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr1
in: #(0 2 0 2 0)
> (array-slice-ref arr (list (::) (:: 0 5 2))) eval:18:0: Type Checker: missing type for top-level
identifier;
either undefined or missing a type annotation
identifier: arr1
in: 2
Functional code that uses whole-array operations often creates many short-lived, intermediate arrays whose elements are referred to only once. The overhead of allocating and filling storage for these arrays can be removed entirely by using nonstrict arrays, sometimes at the cost of making the code’s performance more difficult to reason about. Another bonus is that computations with nonstrict arrays have fewer synchronization points, meaning that they will be easier to parallelize as Racket’s support for parallel computation improves. See Nonstrict Arrays for details.