-
Notifications
You must be signed in to change notification settings - Fork 28
[210_10] 实现 bag 构造器、访问器与谓词 #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # [210_10] 实现 bag 基础能力(SRFI-113) | ||
|
|
||
| ## 任务相关的代码文件 | ||
| - goldfish/srfi/srfi-113.scm | ||
| - goldfish/liii/bag.scm | ||
| - tests/goldfish/liii/bag-test.scm | ||
|
|
||
| ## 如何测试 | ||
| ```bash | ||
| bin/goldfish tests/goldfish/liii/bag-test.scm | ||
| ``` | ||
|
|
||
| ## 2026/01/29 实现 bag 构造器、访问器与谓词 | ||
| ### What | ||
| 实现 SRFI-113 的 bag 基础构造、访问与谓词函数,并在 (liii bag) 中提供默认比较器封装与测试用例。 | ||
|
|
||
| 1. 在 goldfish/srfi/srfi-113.scm 中实现 bag / bag-unfold / bag-member / bag-element-comparator / bag->list,并添加到导出列表 | ||
| 2. 在 goldfish/liii/bag.scm 中提供默认比较器版本的 bag,并导出上述函数 | ||
| 3. 在 tests/goldfish/liii/bag-test.scm 中添加文档注释与覆盖测试(含错误分支) | ||
| 4. 在 goldfish/srfi/srfi-113.scm 中实现 bag? / bag-contains? / bag-empty? / bag-disjoint? 并添加到导出列表 | ||
| 5. 在 goldfish/liii/bag.scm 中导出以上谓词 | ||
| 6. 在 tests/goldfish/liii/bag-test.scm 中添加注释与测试(含类型错误分支) | ||
|
|
||
| ### Why | ||
| 提供多重集(bag)的最小可用接口,用于存储重复元素并支持基础查询与遍历输出。 | ||
|
|
||
| ### How | ||
| 1. bag 使用 comparator 构造,插入时按 comparator 相等性累加计数 | ||
| 2. bag-unfold 使用 unfold 模式生成 bag | ||
| 3. bag-member 返回 bag 中等价元素,未命中返回默认值 | ||
| 4. bag->list 将元素按计数展开为列表 | ||
| 5. bag? 使用 record-type 生成的谓词 | ||
| 6. bag-contains? 使用 comparator 相等性在线性扫描 entries | ||
| 7. bag-empty? 检查 entries 是否为空 | ||
| 8. bag-disjoint? 逐元素比对,找到相等元素立即返回 #f | ||
| 9. 关键路径与类型错误通过测试覆盖 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| ; | ||
| ; Copyright (C) 2026 The Goldfish Scheme Authors | ||
| ; | ||
| ; Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ; you may not use this file except in compliance with the License. | ||
| ; You may obtain a copy of the License at | ||
| ; | ||
| ; http://www.apache.org/licenses/LICENSE-2.0 | ||
| ; | ||
| ; Unless required by applicable law or agreed to in writing, software | ||
| ; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| ; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| ; License for the specific language governing permissions and limitations | ||
| ; under the License. | ||
| ; | ||
|
|
||
| (define-library (liii bag) | ||
| (import (rename (srfi srfi-113) | ||
| (bag make-bag-with-comparator)) | ||
| (only (srfi srfi-113) | ||
| bag-unfold bag-member bag-comparator bag->list | ||
| bag? bag-contains? bag-empty? bag-disjoint?) | ||
| (srfi srfi-128)) | ||
| (export bag bag-unfold bag-member bag-comparator | ||
| bag->list | ||
| bag? bag-contains? bag-empty? bag-disjoint?) | ||
|
|
||
| (define comp (make-default-comparator)) | ||
|
|
||
| (define (bag . elements) | ||
| (apply make-bag-with-comparator comp elements)) | ||
|
|
||
| ) ; end of define-library |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.