Skip to content

Commit

Permalink
!255 rich-list%reverse in (liii lang)
Browse files Browse the repository at this point in the history
* fix bug
* rich-list%reverse in (liii lang)
  • Loading branch information
TREE37 authored and da-liii committed Feb 27, 2025
1 parent 9081134 commit 114929e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions GoldfishLang.tmu
Original file line number Diff line number Diff line change
Expand Up @@ -3329,6 +3329,36 @@
\;
</scm-chunk>

<paragraph|rich-list%reverse>

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

\ \ \ \ (rich-list (reverse data)))

\ \ \ \
</goldfish-chunk>

<\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true>
(let ((lst (rich-list '(1 2 3 4 5))))

\ \ (check (lst :reverse :collect) =\<gtr\> '(5 4 3 2 1)))

\;

(let ((lst (rich-list '(a b c d e))))

\ \ (check (lst :reverse :collect) =\<gtr\> '(e d c b a)))

\;

(let ((lst (rich-list '())))

\ \ (check (lst :reverse :collect) =\<gtr\> '()))

\;
</goldfish-chunk>

<paragraph|rich-list%take>

<\scm-chunk|goldfish/liii/lang.scm|true|true>
Expand Down
3 changes: 3 additions & 0 deletions goldfish/liii/lang.scm
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@
(define (%for-each x)
(for-each x data))

(chained-define (%reverse)
(rich-list (reverse data)))

(define (%take x . xs)
(typed-define (scala-take (data list?) (n integer?))
(cond ((< n 0) '())
Expand Down
9 changes: 9 additions & 0 deletions tests/goldfish/liii/lang-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,15 @@
(check-true (l :contains 1))
(check-false (l :contains 4)))

(let ((lst (rich-list '(1 2 3 4 5))))
(check (lst :reverse :collect) => '(5 4 3 2 1)))

(let ((lst (rich-list '(a b c d e))))
(check (lst :reverse :collect) => '(e d c b a)))

(let ((lst (rich-list '())))
(check (lst :reverse :collect) => '()))

(let ((lst (rich-list '(1 2 3 4 5))))
(check (lst :take -1 :collect) => '())
(check (lst :take 0 :collect) => '())
Expand Down

0 comments on commit 114929e

Please sign in to comment.