Skip to content

Commit

Permalink
!288 Implement size and length of rich-vector in (liii lang)
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Mar 5, 2025
1 parent cc5889a commit fb4ad30
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
54 changes: 54 additions & 0 deletions GoldfishLang.tmu
Original file line number Diff line number Diff line change
Expand Up @@ -4563,6 +4563,24 @@

<section|静态方法>

<paragraph|rich-vector@is-type-of>

<\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true>
(check-true (rich-vector :is-type-of (rich-vector :empty)))

(check-true (rich-vector :is-type-of (rich-vector #(1 2 3))))

\;

(check-false (rich-vector :is-type-of #(1 2 3)))

(check-false (rich-vector :is-type-of 1))

\;

\;
</goldfish-chunk>

<paragraph|rich-vector@range>

<\goldfish-chunk|goldfish/liii/lang.scm|true|true>
Expand Down Expand Up @@ -4673,6 +4691,42 @@
\;
</goldfish-chunk>

<paragraph|rich-vector%length>

<\goldfish-chunk|goldfish/liii/lang.scm|true|true>
(define (%length)

\ \ (vector-length data))

\;
</goldfish-chunk>

<\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true>
(check ($ #() :length) =\<gtr\> 0)

(check ($ #(1 2 3) :length) =\<gtr\> 3)

\;
</goldfish-chunk>

<paragraph|rich-vector%size>

<\goldfish-chunk|goldfish/liii/lang.scm|true|true>
(define (%size)

\ \ (vector-length data))

\;
</goldfish-chunk>

<\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true>
(check ($ #() :size) =\<gtr\> 0)

(check ($ #(1 2 3) :size) =\<gtr\> 3)

\;
</goldfish-chunk>

<paragraph|rich-vector%apply>

<\goldfish-chunk|goldfish/liii/lang.scm|true|true>
Expand Down
6 changes: 6 additions & 0 deletions goldfish/liii/lang.scm
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,12 @@

(define (%collect) data)

(define (%length)
(vector-length data))

(define (%size)
(vector-length data))

(define (%apply n)
(vector-ref data n))

Expand Down
13 changes: 13 additions & 0 deletions tests/goldfish/liii/lang-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@
(check ($ (list "a" "b") :make-string) => "ab")
(check ($ (list "a" "b") :make-string " ") => "a b")

(check-true (rich-vector :is-type-of (rich-vector :empty)))
(check-true (rich-vector :is-type-of (rich-vector #(1 2 3))))

(check-false (rich-vector :is-type-of #(1 2 3)))
(check-false (rich-vector :is-type-of 1))


(check (array :range 1 5) => ($ (vector 1 2 3 4)))
(check (array :range 1 5 2) => ($ (vector 1 3)))
(check (array :range 1 6 2) => ($ (vector 1 3 5)))
Expand All @@ -756,6 +763,12 @@

(check (array :fill 3 #\a) => ($ (vector #\a #\a #\a)))

(check ($ #() :length) => 0)
(check ($ #(1 2 3) :length) => 3)

(check ($ #() :size) => 0)
(check ($ #(1 2 3) :size) => 3)

(check ($ #(1 2 3) :apply 1) => 2)
(check ($ #(1 2 3) 1) => 2)

Expand Down

0 comments on commit fb4ad30

Please # to comment.