Skip to content

Commit

Permalink
!290 rich-list%reduce in (liii lang)
Browse files Browse the repository at this point in the history
  • Loading branch information
TREE37 authored and da-liii committed Mar 5, 2025
1 parent 0333f47 commit a7a9a3c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions GoldfishLang.tmu
Original file line number Diff line number Diff line change
Expand Up @@ -4443,6 +4443,30 @@
\;
</goldfish-chunk>

\;

<paragraph|rich-list%reduce>

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

\ \ (reduce f init data))

\;
</goldfish-chunk>

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

(check ($ '(1 2 3) :reduce + 0) =\<gtr\> 6) \

(check ($ '(2 3 4) :reduce * 1) =\<gtr\> 24) \

(check ($ '(5) :reduce (lambda (x y) (+ x y 10)) 0) =\<gtr\> 5)

\;
</goldfish-chunk>

<section|转换器>

<paragraph|rich-list%to-string>
Expand Down
3 changes: 3 additions & 0 deletions goldfish/liii/lang.scm
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,9 @@
(loop (cons elem result) (cdr data) ht))
(loop result (cdr data) ht)))))))

(define (%reduce f init)
(reduce f init data))

(define (%to-string)
(object->string data))

Expand Down
5 changes: 5 additions & 0 deletions tests/goldfish/liii/lang-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,11 @@
(check ($ '() :distinct :collect)
=> '())

(check ($ '() :reduce + 0) => 0)
(check ($ '(1 2 3) :reduce + 0) => 6)
(check ($ '(2 3 4) :reduce * 1) => 24)
(check ($ '(5) :reduce (lambda (x y) (+ x y 10)) 0) => 5)

(check (object->string ($ '(1 2 3))) => "(1 2 3)")

(let1 l (rich-list (list 1 2 3))
Expand Down

0 comments on commit a7a9a3c

Please # to comment.