From 28fc5bf55e88488e5baafc015698005c4c28b568 Mon Sep 17 00:00:00 2001 From: jiadong Date: Tue, 21 Oct 2025 20:51:04 +0800 Subject: [PATCH] =?UTF-8?q?[201=5F18]=20=E4=B8=BA=20rich-vector=20?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- devel/201_16.md | 2 +- devel/201_17.md | 8 +-- devel/201_18.md | 2 +- tests/goldfish/liii/rich-vector-test.scm | 87 +++++++++++++++++------- 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/devel/201_16.md b/devel/201_16.md index 66f10e8e..15212368 100644 --- a/devel/201_16.md +++ b/devel/201_16.md @@ -22,7 +22,7 @@ + [x] vector-copy! + [x] vector->string + [x] string->vector -+ [ ] reverse-list->vector ++ [x] reverse-list->vector ### SRFI-133 函数 + [x] vector-empty? diff --git a/devel/201_17.md b/devel/201_17.md index ded60d51..27fe9f04 100644 --- a/devel/201_17.md +++ b/devel/201_17.md @@ -9,10 +9,10 @@ + [x] bitwise-eqv + [x] bitwise-or + [x] bitwise-nor -+ [ ] bitwise-nand -+ [ ] bit-count -+ [ ] bitwise-orc1 -+ [ ] bitwise-orc2 ++ [x] bitwise-nand ++ [x] bit-count ++ [x] bitwise-orc1 ++ [x] bitwise-orc2 + [x] bitwise-andc1 + [x] bitwise-andc2 + [x] arithmetic-shift diff --git a/devel/201_18.md b/devel/201_18.md index 948bde41..260402f9 100644 --- a/devel/201_18.md +++ b/devel/201_18.md @@ -21,7 +21,7 @@ bin/goldfish -m r7rs tests/goldfish/liii/rich-vector-test.scm ``` ### 构造函数和基础方法 -+ [] rich-vector ++ [x] rich-vector + [x] rich-vector@empty + [x] rich-vector@fill + [ ] rich-vector@range diff --git a/tests/goldfish/liii/rich-vector-test.scm b/tests/goldfish/liii/rich-vector-test.scm index 6c552be2..0e3bf43d 100644 --- a/tests/goldfish/liii/rich-vector-test.scm +++ b/tests/goldfish/liii/rich-vector-test.scm @@ -6,6 +6,68 @@ (check-set-mode! 'report-failed) +#| +rich-vector +创建rich-vector对象的构造函数。 + +语法 +---- +(rich-vector data) + +参数 +---- +data : vector +用于初始化rich-vector的向量数据。 + +返回值 +----- +以rich-vector形式返回包装后的向量对象。 + +说明 +---- +将普通向量包装为rich-vector对象,提供丰富的函数式操作方法。 + +边界条件 +-------- +- 空向量:创建空的rich-vector +- 非空向量:创建包含指定元素的rich-vector +- 非向量参数:抛出type-error + +性能特征 +-------- +- 时间复杂度:O(1),直接包装现有向量 +- 空间复杂度:O(n),需要存储向量引用 + +兼容性 +------ +- 支持所有rich-vector实例方法 +- 与普通向量操作兼容 +|# + +;;; 测试构造函数 +(let ((v (rich-vector #(1 2 3)))) + (check (v :is-instance-of 'rich-vector) => #t) + (check (= (v :length) 3) => #t)) + +;;; 测试基本操作 +(let ((v (rich-vector #(1 2 3)))) + (check (= (v :fold 0 +) 6) => #t) + (check (= (v :head) 1) => #t) + (check (= (v :last) 3) => #t)) + +;;; 测试元素查找 +(let ((v (rich-vector #(1 2 3)))) + (check (= (v :index-of 2) 1) => #t) + (check (v :contains 2) => #t)) + +;;; 测试转换 +(let ((v (rich-vector #(1 2 3)))) + (check (equal? (v :to-list) '(1 2 3)) => #t)) + +;;; 测试函数式操作 +(let ((v (rich-vector #(1 2 3)))) + (check (equal? ((v :map (lambda (x) (* x 2))) :to-list) '(2 4 6)) => #t) + (check (equal? ((v :filter (lambda (x) (> x 1))) :to-list) '(2 3)) => #t)) #| rich-vector@empty @@ -65,31 +127,6 @@ args : list (check (equal? (empty-v :to-list) '()) => #t) (check (equal? (empty-v :to-string) "#()") => #t)) -;;; 测试构造函数 -(let ((v (rich-vector #(1 2 3)))) - (check (v :is-instance-of 'rich-vector) => #t) - (check (= (v :length) 3) => #t)) - -;;; 测试基本操作 -(let ((v (rich-vector #(1 2 3)))) - (check (= (v :fold 0 +) 6) => #t) - (check (= (v :head) 1) => #t) - (check (= (v :last) 3) => #t)) - -;;; 测试元素查找 -(let ((v (rich-vector #(1 2 3)))) - (check (= (v :index-of 2) 1) => #t) - (check (v :contains 2) => #t)) - -;;; 测试转换 -(let ((v (rich-vector #(1 2 3)))) - (check (equal? (v :to-list) '(1 2 3)) => #t)) - -;;; 测试函数式操作 -(let ((v (rich-vector #(1 2 3)))) - (check (equal? ((v :map (lambda (x) (* x 2))) :to-list) '(2 4 6)) => #t) - (check (equal? ((v :filter (lambda (x) (> x 1))) :to-list) '(2 3)) => #t)) - #| rich-vector@fill 创建一个包含重复元素的rich-vector对象。 -- Gitee