write arrays with brackets in tests
The tests spelled out (¤ ...), what [...] reads into, which nobody writes. The reader's own tests keep it: there it is the point.
This commit is contained in:
@@ -366,7 +366,7 @@ compiles."
|
|||||||
(emits? "(fn f ((c (closure ((long)) int))) int (return (c 1)))"
|
(emits? "(fn f ((c (closure ((long)) int))) int (return (c 1)))"
|
||||||
"ƛc.code(&ƛc.env, ƛa0)"))
|
"ƛc.code(&ƛc.env, ƛa0)"))
|
||||||
(test-assert "a subscript receiver is evaluated once"
|
(test-assert "a subscript receiver is evaluated once"
|
||||||
(emits? "(fn f ((t (¤ (closure ((int)) int) 4)) (i int)) int (return ((¤ t (++ i)) 1)))"
|
(emits? "(fn f ((t [(closure ((int)) int) 4]) (i int)) int (return ([t (++ i)] 1)))"
|
||||||
"ƛint_int_call(t[++i], 1)"))
|
"ƛint_int_call(t[++i], 1)"))
|
||||||
(test-assert "so is a member receiver"
|
(test-assert "so is a member receiver"
|
||||||
(emits? "(struct h ((cb (closure ((int)) int))))
|
(emits? "(struct h ((cb (closure ((int)) int))))
|
||||||
@@ -487,7 +487,7 @@ compiles."
|
|||||||
(test-group "macro list accessors"
|
(test-group "macro list accessors"
|
||||||
(test-assert "third reads an array's length"
|
(test-assert "third reads an array's length"
|
||||||
(emits? "(defmacro (len t) (third t))
|
(emits? "(defmacro (len t) (third t))
|
||||||
(fn f () int (return (len (¤ int 7))))"
|
(fn f () int (return (len [int 7])))"
|
||||||
"return 7;"))
|
"return 7;"))
|
||||||
(test-assert "second reads a tag"
|
(test-assert "second reads a tag"
|
||||||
(emits? "(defmacro (tag t) (symbol->string (second t)))
|
(emits? "(defmacro (tag t) (symbol->string (second t)))
|
||||||
@@ -561,7 +561,7 @@ compiles."
|
|||||||
(fn f ((s (struct p))) void (var x (* _) (& s)))"
|
(fn f ((s (struct p))) void (var x (* _) (& s)))"
|
||||||
"struct p* x = &s"))
|
"struct p* x = &s"))
|
||||||
(test-assert "a wildcard inside an array"
|
(test-assert "a wildcard inside an array"
|
||||||
(emits? (in-fn "(var t (¤ _ 3) #((¤ int 3) : 1 2 3))") "int t[3]"))
|
(emits? (in-fn "(var t [_ 3] #([int 3] : 1 2 3))") "int t[3]"))
|
||||||
;; a compound literal carries its own type, where a brace
|
;; a compound literal carries its own type, where a brace
|
||||||
;; initializer has none and takes one from its context
|
;; initializer has none and takes one from its context
|
||||||
(test-assert "a compound literal answers a bare wildcard"
|
(test-assert "a compound literal answers a bare wildcard"
|
||||||
@@ -572,11 +572,11 @@ compiles."
|
|||||||
(reports? (in-fn "(var x _ #(1 2))") "cannot infer the type"))
|
(reports? (in-fn "(var x _ #(1 2))") "cannot infer the type"))
|
||||||
;; ...but its elements still solve the hole in an array type
|
;; ...but its elements still solve the hole in an array type
|
||||||
(test-assert "elements solve an array's element type"
|
(test-assert "elements solve an array's element type"
|
||||||
(emits? (in-fn "(var t (¤ _ 4) #(0 1 4 9))") "int t[4] = {0, 1, 4, 9}"))
|
(emits? (in-fn "(var t [_ 4] #(0 1 4 9))") "int t[4] = {0, 1, 4, 9}"))
|
||||||
(test-assert "including when there are fewer than the length"
|
(test-assert "including when there are fewer than the length"
|
||||||
(emits? (in-fn "(var t (¤ _ 10) #(1 2))") "int t[10] = {1, 2}"))
|
(emits? (in-fn "(var t [_ 10] #(1 2))") "int t[10] = {1, 2}"))
|
||||||
(test-assert "and they have to agree with each other"
|
(test-assert "and they have to agree with each other"
|
||||||
(reports? (in-fn "(var t (¤ _ 2) #(1 \"s\"))") "type mismatch"))
|
(reports? (in-fn "(var t [_ 2] #(1 \"s\"))") "type mismatch"))
|
||||||
;; a closure type reaches the solver as the struct that stands for
|
;; a closure type reaches the solver as the struct that stands for
|
||||||
;; it, which is the spelling `parse-type' knows
|
;; it, which is the spelling `parse-type' knows
|
||||||
(test-assert "a closure, from the signature that produced it"
|
(test-assert "a closure, from the signature that produced it"
|
||||||
@@ -680,28 +680,28 @@ compiles."
|
|||||||
(emits? (in-fn "(var n int (+ (- a) b))") "-a + b")))
|
(emits? (in-fn "(var n int (+ (- a) b))") "-a + b")))
|
||||||
|
|
||||||
;; An array bound was taken only when it was an integer literal, so a
|
;; An array bound was taken only when it was an integer literal, so a
|
||||||
;; symbolic one fell into the type: `(¤ int N)' came out `int N a[]'.
|
;; symbolic one fell into the type: `[int N]' came out `int N a[]'.
|
||||||
(test-group "array bounds"
|
(test-group "array bounds"
|
||||||
(test-assert "a symbolic bound"
|
(test-assert "a symbolic bound"
|
||||||
(emits? "(define N 4) (struct s ((a (¤ int N))))" "int a[N]"))
|
(emits? "(define N 4) (struct s ((a [int N])))" "int a[N]"))
|
||||||
(test-assert "an expression bound"
|
(test-assert "an expression bound"
|
||||||
(emits? "(define N 4) (struct s ((a (¤ char (* 2 N)))))" "char a[2 * N]"))
|
(emits? "(define N 4) (struct s ((a [char (* 2 N)])))" "char a[2 * N]"))
|
||||||
(test-assert "an integer bound still works"
|
(test-assert "an integer bound still works"
|
||||||
(emits? "(struct s ((a (¤ int 4))))" "int a[4]"))
|
(emits? "(struct s ((a [int 4])))" "int a[4]"))
|
||||||
;; ...and it is spelled the way the same name is in an expression
|
;; ...and it is spelled the way the same name is in an expression
|
||||||
(test-assert "a bound's name is converted"
|
(test-assert "a bound's name is converted"
|
||||||
(emits? (in-fn "(var xs (¤ u16 CHUNK-AREA))") "u16 xs[CHUNK_AREA]"))
|
(emits? (in-fn "(var xs [u16 CHUNK-AREA])") "u16 xs[CHUNK_AREA]"))
|
||||||
(test-assert "so is one inside an expression bound"
|
(test-assert "so is one inside an expression bound"
|
||||||
(emits? (in-fn "(var xs (¤ u16 (* 2 CHUNK-AREA)))") "u16 xs[2 * CHUNK_AREA]"))
|
(emits? (in-fn "(var xs [u16 (* 2 CHUNK-AREA)])") "u16 xs[2 * CHUNK_AREA]"))
|
||||||
;; a multi-word type is keywords all the way down, so a trailing
|
;; a multi-word type is keywords all the way down, so a trailing
|
||||||
;; keyword belongs to the type and leaves the array unsized
|
;; keyword belongs to the type and leaves the array unsized
|
||||||
(test-assert "a multi-word type is not a bound"
|
(test-assert "a multi-word type is not a bound"
|
||||||
(emits? "(struct s ((a (¤ unsigned int))))" "unsigned int a[]"))
|
(emits? "(struct s ((a [unsigned int])))" "unsigned int a[]"))
|
||||||
;; ...and a tag always follows its keyword
|
;; ...and a tag always follows its keyword
|
||||||
(test-assert "nor is an aggregate tag"
|
(test-assert "nor is an aggregate tag"
|
||||||
(emits? "(struct t ((z int))) (struct s ((a (¤ struct t))))" "struct t a[]"))
|
(emits? "(struct t ((z int))) (struct s ((a [struct t])))" "struct t a[]"))
|
||||||
(test-assert "nor one behind a pointer"
|
(test-assert "nor one behind a pointer"
|
||||||
(emits? "(struct t ((z int))) (struct s ((a (¤ * struct t))))" "struct t* a[]")))
|
(emits? "(struct t ((z int))) (struct s ((a [* struct t])))" "struct t* a[]")))
|
||||||
|
|
||||||
;; `sizeof' takes a type or an expression, and `(* x)' is either.
|
;; `sizeof' takes a type or an expression, and `(* x)' is either.
|
||||||
;; What is in scope says which: a name C alone knows is a type
|
;; What is in scope says which: a name C alone knows is a type
|
||||||
@@ -715,7 +715,7 @@ compiles."
|
|||||||
(test-assert "a multi-word type"
|
(test-assert "a multi-word type"
|
||||||
(emits? (in-fn "(var n size-t (sizeof (unsigned int)))") "sizeof(unsigned int)"))
|
(emits? (in-fn "(var n size-t (sizeof (unsigned int)))") "sizeof(unsigned int)"))
|
||||||
(test-assert "an array type"
|
(test-assert "an array type"
|
||||||
(emits? (in-fn "(var n size-t (sizeof (¤ int 4)))") "sizeof(int [4])"))
|
(emits? (in-fn "(var n size-t (sizeof [int 4]))") "sizeof(int [4])"))
|
||||||
(test-assert "a dereference of a local"
|
(test-assert "a dereference of a local"
|
||||||
(emits? (in-fn "(var p (* int) 0) (var n size-t (sizeof (* p)))") "sizeof(*p)"))
|
(emits? (in-fn "(var p (* int) 0) (var n size-t (sizeof (* p)))") "sizeof(*p)"))
|
||||||
(test-assert "of a parameter"
|
(test-assert "of a parameter"
|
||||||
@@ -723,7 +723,7 @@ compiles."
|
|||||||
(test-assert "of a call"
|
(test-assert "of a call"
|
||||||
(emits? (in-fn "(var n size-t (sizeof (* (g))))") "sizeof(*g())"))
|
(emits? (in-fn "(var n size-t (sizeof (* (g))))") "sizeof(*g())"))
|
||||||
(test-assert "a subscript"
|
(test-assert "a subscript"
|
||||||
(emits? (in-fn "(var xs (¤ int 4)) (var n size-t (sizeof (¤ xs 0)))") "sizeof(xs[0])")))
|
(emits? (in-fn "(var xs [int 4]) (var n size-t (sizeof [xs 0]))") "sizeof(xs[0])")))
|
||||||
|
|
||||||
;; A define's body was pasted unwalked, and unparenthesised: `cast'
|
;; A define's body was pasted unwalked, and unparenthesised: `cast'
|
||||||
;; stayed a call, and (* x D) regrouped with D's own operator
|
;; stayed a call, and (* x D) regrouped with D's own operator
|
||||||
@@ -750,7 +750,7 @@ compiles."
|
|||||||
(test-assert "of a pointer"
|
(test-assert "of a pointer"
|
||||||
(emits? "(typedef cstr (* const char))" "typedef const char * cstr;"))
|
(emits? "(typedef cstr (* const char))" "typedef const char * cstr;"))
|
||||||
(test-assert "of an array"
|
(test-assert "of an array"
|
||||||
(emits? "(typedef vec4 (¤ float 4))" "typedef float vec4[4];"))
|
(emits? "(typedef vec4 [float 4])" "typedef float vec4[4];"))
|
||||||
(test-assert "of a function pointer"
|
(test-assert "of a function pointer"
|
||||||
(emits? "(typedef colour-fn (fn ((i32)) u32))"
|
(emits? "(typedef colour-fn (fn ((i32)) u32))"
|
||||||
"typedef u32 (*colour_fn)(i32);")))
|
"typedef u32 (*colour_fn)(i32);")))
|
||||||
|
|||||||
@@ -66,12 +66,12 @@
|
|||||||
|
|
||||||
(printf "Through a parameter: %d\n" (apply-twice (make-adder 50) 10))
|
(printf "Through a parameter: %d\n" (apply-twice (make-adder 50) 10))
|
||||||
|
|
||||||
(var table (¤ (closure ((int)) int) 3))
|
(var table [(closure ((int)) int) 3])
|
||||||
(var i int 0)
|
(var i int 0)
|
||||||
(for (= i 0) (< i 3) (++ i)
|
(for (= i 0) (< i 3) (++ i)
|
||||||
(= (¤ table i) (make-adder i)))
|
(= [table i] (make-adder i)))
|
||||||
(printf "From an array: %d %d %d\n"
|
(printf "From an array: %d %d %d\n"
|
||||||
((¤ table 0) 1) ((¤ table 1) 1) ((¤ table 2) 1))
|
([table 0] 1) ([table 1] 1) ([table 2] 1))
|
||||||
|
|
||||||
;; the index must be evaluated once, so `i' ends at 1 and not 2 --
|
;; the index must be evaluated once, so `i' ends at 1 and not 2 --
|
||||||
;; read in a separate statement, since reading and bumping it in one
|
;; read in a separate statement, since reading and bumping it in one
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
;; an array literal decays the way an array does
|
;; an array literal decays the way an array does
|
||||||
(var a (* int) #([int 3] : 10 20 30))
|
(var a (* int) #([int 3] : 10 20 30))
|
||||||
(printf "array %d %d %d\n" (¤ a 0) (¤ a 1) (¤ a 2))
|
(printf "array %d %d %d\n" [a 0] [a 1] [a 2])
|
||||||
|
|
||||||
(printf "argument %d\n" (sum #(struct point : 2 4)))
|
(printf "argument %d\n" (sum #(struct point : 2 4)))
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@
|
|||||||
;;;
|
;;;
|
||||||
;;; 1. SETTLED. `type-match' took `_' on the pattern side, so
|
;;; 1. SETTLED. `type-match' took `_' on the pattern side, so
|
||||||
;;; `(closure _ int)' above is one clause rather than one per
|
;;; `(closure _ int)' above is one clause rather than one per
|
||||||
;;; signature, and `(* _)' and `(¤ _ _)' say "any pointer" and "any
|
;;; signature, and `(* _)' and `[_ _]' say "any pointer" and "any
|
||||||
;;; array". A `_' written last takes the rest, since a type's words
|
;;; array". A `_' written last takes the rest, since a type's words
|
||||||
;;; are spread and not nested: `(* const char)' is three elements.
|
;;; are spread and not nested: `(* const char)' is three elements.
|
||||||
;;; Nothing destructures -- a macro body is Scheme and a type is a
|
;;; Nothing destructures -- a macro body is Scheme and a type is a
|
||||||
|
|||||||
@@ -62,10 +62,10 @@
|
|||||||
(printf "increment: %d\n" inc)
|
(printf "increment: %d\n" inc)
|
||||||
|
|
||||||
;; an array operand decays, so this is a pointer and not an array
|
;; an array operand decays, so this is a pointer and not an array
|
||||||
(var xs (¤ int 4) #(1 2 3 4))
|
(var xs [int 4] #(1 2 3 4))
|
||||||
(var p _ (+ xs 1))
|
(var p _ (+ xs 1))
|
||||||
(var q _ (+ 1 xs))
|
(var q _ (+ 1 xs))
|
||||||
(var names (¤ (* const char) 2) #("hi" "there"))
|
(var names [(* const char) 2] #("hi" "there"))
|
||||||
(var np _ (+ names 1))
|
(var np _ (+ names 1))
|
||||||
(printf "decayed: %d %d %s\n" (* p) (* q) (* np))
|
(printf "decayed: %d %d %s\n" (* p) (* q) (* np))
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
;;; Three questions about a written type that used to be answered in
|
;;; Three questions about a written type that used to be answered in
|
||||||
;;; three places and disagreed: is `(a b)' a named parameter or a bare
|
;;; three places and disagreed: is `(a b)' a named parameter or a bare
|
||||||
;;; type, is the last element of a `¤' its bound or the last word of
|
;;; type, is the last element of a `[...]' its bound or the last word of
|
||||||
;;; its element type, and what is one element of an array.
|
;;; its element type, and what is one element of an array.
|
||||||
;;;
|
;;;
|
||||||
;;; They are one question -- where does the type end -- so the answer
|
;;; They are one question -- where does the type end -- so the answer
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
(typedef small int)
|
(typedef small int)
|
||||||
(typedef cstr (* const char))
|
(typedef cstr (* const char))
|
||||||
(typedef vec4 (¤ float 4))
|
(typedef vec4 [float 4])
|
||||||
(typedef unary (fn ((small)) small))
|
(typedef unary (fn ((small)) small))
|
||||||
|
|
||||||
(define CAP 2)
|
(define CAP 2)
|
||||||
@@ -45,40 +45,40 @@
|
|||||||
|
|
||||||
(pub fn main () int
|
(pub fn main () int
|
||||||
;; an element keeps every word of its type, tag and all
|
;; an element keeps every word of its type, tag and all
|
||||||
(var pts (¤ (struct point) 2) #(#((struct point) : 1 2)
|
(var pts [(struct point) 2] #(#((struct point) : 1 2)
|
||||||
#((struct point) : 3 4)))
|
#((struct point) : 3 4)))
|
||||||
(var p _ (¤ pts 1))
|
(var p _ [pts 1])
|
||||||
(printf "aggregate element: %d %d\n" (. p x) (. p y))
|
(printf "aggregate element: %d %d\n" (. p x) (. p y))
|
||||||
|
|
||||||
(var names (¤ (* const char) 2) #("hi" "there"))
|
(var names [(* const char) 2] #("hi" "there"))
|
||||||
(var s _ (¤ names 1))
|
(var s _ [names 1])
|
||||||
(printf "pointer element: %s\n" s)
|
(printf "pointer element: %s\n" s)
|
||||||
|
|
||||||
(var nums (¤ unsigned int 3) #(7 8 9))
|
(var nums [unsigned int 3] #(7 8 9))
|
||||||
(var u _ (¤ nums 2))
|
(var u _ [nums 2])
|
||||||
(printf "multi-word element: %u\n" u)
|
(printf "multi-word element: %u\n" u)
|
||||||
|
|
||||||
;; subscripting a pointer answers the same as subscripting an array
|
;; subscripting a pointer answers the same as subscripting an array
|
||||||
(var q (* (struct point)) (& (¤ pts 0)))
|
(var q (* (struct point)) (& [pts 0]))
|
||||||
(var r _ (¤ q 1))
|
(var r _ [q 1])
|
||||||
(printf "through a pointer: %d\n" (+ (. r x) (* 13 (. r y))))
|
(printf "through a pointer: %d\n" (+ (. r x) (* 13 (. r y))))
|
||||||
|
|
||||||
;; the last word of an unsized array's type is not its bound: neither
|
;; the last word of an unsized array's type is not its bound: neither
|
||||||
;; a typedef name nor the target of a `*' can be one
|
;; a typedef name nor the target of a `*' can be one
|
||||||
(var tail (¤ const small) #(1 2))
|
(var tail [const small] #(1 2))
|
||||||
(printf "unsized of a typedef: %d %d\n" (¤ tail 0) (¤ tail 1))
|
(printf "unsized of a typedef: %d %d\n" [tail 0] [tail 1])
|
||||||
|
|
||||||
(var one size-t 5)
|
(var one size-t 5)
|
||||||
(var sizes (¤ * size-t) #((& one)))
|
(var sizes [* size-t] #((& one)))
|
||||||
(var w _ (¤ sizes 0))
|
(var w _ [sizes 0])
|
||||||
(printf "unsized of a pointer: %d\n" (cast (* w) int))
|
(printf "unsized of a pointer: %d\n" (cast (* w) int))
|
||||||
|
|
||||||
;; ...but after a whole type, a name is: `size-t' is a typedef only C
|
;; ...but after a whole type, a name is: `size-t' is a typedef only C
|
||||||
;; knows of, and `(* const char)' a type grouped into one element
|
;; knows of, and `(* const char)' a type grouped into one element
|
||||||
(var ws (¤ size-t CAP) #(3 4))
|
(var ws [size-t CAP] #(3 4))
|
||||||
(var gs (¤ (* const char) CAP) #("a" "b"))
|
(var gs [(* const char) CAP] #("a" "b"))
|
||||||
(printf "named bound: %zu %zu %s\n"
|
(printf "named bound: %zu %zu %s\n"
|
||||||
(/ (sizeof ws) (sizeof (¤ ws 0))) (¤ ws 1) (¤ gs 1))
|
(/ (sizeof ws) (sizeof [ws 0])) [ws 1] [gs 1])
|
||||||
|
|
||||||
;; the same question in type position: `(fn ((unsigned int)) int)'
|
;; the same question in type position: `(fn ((unsigned int)) int)'
|
||||||
;; takes one parameter, not two
|
;; takes one parameter, not two
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
(var greeting cstr "hi")
|
(var greeting cstr "hi")
|
||||||
(var v vec4 #(1.0 2.0 3.0 4.0))
|
(var v vec4 #(1.0 2.0 3.0 4.0))
|
||||||
(var op unary twice)
|
(var op unary twice)
|
||||||
(printf "typedefs: %s %zu %d\n" greeting (/ (sizeof v) (sizeof (¤ v 0))) (op 1))
|
(printf "typedefs: %s %zu %d\n" greeting (/ (sizeof v) (sizeof [v 0])) (op 1))
|
||||||
|
|
||||||
;; `(* T)' is a type or a dereference, and only what is in scope says
|
;; `(* T)' is a type or a dereference, and only what is in scope says
|
||||||
(printf "sizeof a pointer type: %d %d\n"
|
(printf "sizeof a pointer type: %d %d\n"
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
(fn origin-x ((p (* (struct point)))) int
|
(fn origin-x ((p (* (struct point)))) int
|
||||||
(return (. (* p) x)))
|
(return (. (* p) x)))
|
||||||
|
|
||||||
(fn second-of ((xs (¤ float 4))) float
|
(fn second-of ((xs [float 4])) float
|
||||||
(return (¤ xs 1)))
|
(return [xs 1]))
|
||||||
|
|
||||||
(fn say ((fmt (* const char)) ...) void
|
(fn say ((fmt (* const char)) ...) void
|
||||||
(var ap va-list)
|
(var ap va-list)
|
||||||
@@ -43,8 +43,8 @@
|
|||||||
(var f (fn ((* (struct point))) int) origin-x)
|
(var f (fn ((* (struct point))) int) origin-x)
|
||||||
(printf "aggregate: %d\n" (f (& p)))
|
(printf "aggregate: %d\n" (f (& p)))
|
||||||
|
|
||||||
(var xs (¤ float 4) #(1.5 2.5 3.5 4.5))
|
(var xs [float 4] #(1.5 2.5 3.5 4.5))
|
||||||
(var g (fn ((¤ float 4)) float) second-of)
|
(var g (fn ([float 4]) float) second-of)
|
||||||
(printf "array: %g\n" (g xs))
|
(printf "array: %g\n" (g xs))
|
||||||
|
|
||||||
(say "variadic: %d %s\n" 1 "two")
|
(say "variadic: %d %s\n" 1 "two")
|
||||||
|
|||||||
@@ -44,11 +44,11 @@
|
|||||||
(var pp _ (& p))
|
(var pp _ (& p))
|
||||||
(printf "pointers: %d %g\n" (. pp x) (. pp y))
|
(printf "pointers: %d %g\n" (. pp x) (. pp y))
|
||||||
|
|
||||||
(var table (¤ int 3))
|
(var table [int 3])
|
||||||
(= (¤ table 0) 10)
|
(= [table 0] 10)
|
||||||
(= (¤ table 1) 20)
|
(= [table 1] 20)
|
||||||
(var first _ (¤ table 0))
|
(var first _ [table 0])
|
||||||
(var second _ (¤ table 1))
|
(var second _ [table 1])
|
||||||
(printf "arrays: %d\n" (+ first second))
|
(printf "arrays: %d\n" (+ first second))
|
||||||
|
|
||||||
;; a for opens a scope, and its initializer is declared inside it
|
;; a for opens a scope, and its initializer is declared inside it
|
||||||
@@ -103,7 +103,7 @@
|
|||||||
;; a brace initializer has no type of its own, but its elements solve
|
;; a brace initializer has no type of its own, but its elements solve
|
||||||
;; the hole in the array type around it -- and the length stays as
|
;; the hole in the array type around it -- and the length stays as
|
||||||
;; written, whether or not every slot is initialized
|
;; written, whether or not every slot is initialized
|
||||||
(var squares (¤ _ 4) #(0 1 4 9))
|
(var squares [_ 4] #(0 1 4 9))
|
||||||
(var sparse (¤ _ 8) #(0 1))
|
(var sparse [_ 8] #(0 1))
|
||||||
(printf "from elements: %d %d %d\n" (¤ squares 2) (¤ squares 3) (¤ sparse 7))
|
(printf "from elements: %d %d %d\n" [squares 2] [squares 3] [sparse 7])
|
||||||
(return 0))
|
(return 0))
|
||||||
|
|||||||
Reference in New Issue
Block a user