Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 3 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

Goldfish Scheme is a Scheme interpreter with the following features:
+ R7RS-small compatible
+ Scala-like functional collection
+ Python-like versatile standard library
+ Small and fast

Expand All @@ -17,47 +16,6 @@ Goldfish Scheme is a Scheme interpreter with the following features:

(person :name "Alice" :age 3)
```
### Unicode Support
``` scheme
(import (liii lang))

($ "你好,世界" 0) ; => 你
($ "你好,世界" 4) ; => 界
($ "你好,世界" :length) ; => 5
```

### Functional Data Pipeline
![](r7rs_vs_goldfish.png)

With `prime?` provided, filter twin prime numbers in this way:
``` scheme
(import (liii lang))

(($ 1 :to 100)
:filter prime?
:filter (lambda (x) (prime? (+ x 2)))
:map (lambda (x) (cons x (+ x 2)))
:collect)
```

### Scala like case class
``` scheme
(define-case-class person
((name string?)
(age integer?))

(define (%to-string)
(string-append "I am " name " " (number->string age) " years old!"))
(define (%greet x)
(string-append "Hi " x ", " (%to-string))))

(define bob (person "Bob" 21))

(bob :to-string) ; => "I am Bob 21 years old!"
(bob :greet "Alice") ; => "Hi Alice, I am Bob 21 years old!"
```

> **Performance Warning**: `define-case-class` is implemented via macros and has significant performance overhead. It is suitable for hand-written code and prototyping, but **not recommended for AI-generated code or production deployments**.

## Simplicity is Beauty
Goldfish Scheme still follows the same principle of simplicity as S7 Scheme. Currently, Goldfish Scheme only depends on [S7 Scheme](https://ccrma.stanford.edu/software/s7/), [tbox](https://gitee.com/tboox/tbox) and C++ standard library defined in C++ 98.
Expand All @@ -66,16 +24,6 @@ Just like S7 Scheme, [src/goldfish.hpp](src/goldfish.hpp) and [src/goldfish.cpp]


## Standard Library
### Scala-like collections
| Library | Description |
|---------|-------------|
| [(liii rich-char)](tests/goldfish/liii/rich-char-test.scm) | boxed char with rich char and instance methods |
| [(liii rich-string)](tests/goldfish/liii/rich-string-test.scm) | boxed string with rich char and instance methods |
| [(liii rich-list)](tests/goldfish/liii/rich-list-test.scm) | boxed list with rich static and instance methods |
| [(liii rich-vector)](tests/goldfish/liii/rich-vector-test.scm) | boxed vector with rich static and instance methods |
| [(liii rich-hash-table)](tests/goldfish/liii/rich-hash-table-test.scm) | boxed hash-table with rich static and instance methods |
| [(liii rich-path)](tests/goldfish/liii/rich-path-test.scm) | boxed path with rich static and instance methods |

### Python-like standard library

| Library | Description | Example functions |
Expand All @@ -95,6 +43,8 @@ Just like S7 Scheme, [src/goldfish.hpp](src/goldfish.hpp) and [src/goldfish.cpp]
| [(liii range)](goldfish/liii/range.scm) | Range Library | `numeric-range`, `iota` |
| [(liii option)](goldfish/liii/option.scm) | Option Type Library | `option?`, `option-map`, `option-flatten` |
| [(liii uuid)](goldfish/liii/uuid.scm) | UUID generation | `uuid4` |
| [(liii http)](goldfish/liii/http.scm) | HTTP client library | `http-get`, `http-post`, `http-head` |
| [(liii json)](goldfish/liii/json.scm) | JSON parsing and manipulation | `string->json`, `json->string` |


### SRFI
Expand Down Expand Up @@ -131,26 +81,6 @@ Besides the Goldfish Scheme interpreter, a nice structured [Goldfish Scheme REPL

The following guide will help you build and install Goldfish step by step.

### GNU/Linux
Here are commandlines to build it on Debian bookworm:
```
sudo apt install xmake git unzip curl g++
git clone https://gitee.com/LiiiLabs/goldfish.git
# git clone https://github.com/LiiiLabs/goldfish.git
cd goldfish
xmake b goldfish
bin/gf --version
```
You can also install it to `/opt`:
```
sudo xmake i -o /opt/goldfish --root
/opt/goldfish/bin/gf
```
For uninstallation, just:
```
sudo rm -rf /opt/goldfish
```

### macOS
Here are commandlines to build it on macOS:
```
Expand Down Expand Up @@ -232,7 +162,7 @@ You can also load and evaluate a Scheme file directly:
`-m` or `--mode` helps you specify the standard library mode:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 liii 模式遗漏 (liii string) 导入

README 描述 liii 模式仅预加载 (liii base)(liii error),但 src/goldfish.hppcustomize_goldfish_by_mode(第 4104–4105 行)的实际代码为:

s7_eval_c_string (sc, "(import (liii base) (liii error) (liii string))");

新增的 REPL 欢迎消息(第 4554 行)也已正确反映了这三个库,但 README 的说明遗漏了 (liii string)

建议修正为:

Suggested change
`-m` or `--mode` helps you specify the standard library mode:
+ `liii`: Goldfish Scheme with `(liii base)`, `(liii error)` and `(liii string)`


+ `default`: `-m default` is the equiv of `-m liii`
+ `liii`: Goldfish Scheme with `(liii oop)`, `(liii base)` and `(liii error)`
+ `liii`: Goldfish Scheme with `(liii base)` and `(liii error)`
+ `scheme`: Goldfish Scheme with `(liii base)` and `(liii error)`
+ `sicp`: S7 Scheme with `(scheme base)` and `(srfi sicp)`
+ `r7rs`: S7 Scheme with `(scheme base)`
Expand Down
79 changes: 4 additions & 75 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

金鱼Scheme 是一个 Scheme 解释器,具有以下特性:
+ 兼容 R7RS-small 标准
+ 提供类似 Scala 的函数式集合库
+ 提供类似 Python 的功能丰富的标准库
+ 小巧且快速

Expand All @@ -17,70 +16,18 @@

(person :name "Alice" :age 3)
```
### Unicode支持
``` scheme
(import (liii lang))

($ "你好,世界" 0) ; => 你
($ "你好,世界" 4) ; => 界
($ "你好,世界" :length) ; => 5
```

### 函数式数据管道
![](r7rs_vs_goldfish.png)

在`prime?`已提供的情况下,用如下方法过滤出1到100的孪生质数(致敬张益唐):
``` scheme
(import (liii lang))

(($ 1 :to 100)
:filter prime?
:filter (lambda (x) (prime? (+ x 2)))
:map (lambda (x) (cons x (+ x 2)))
:collect)
```

### 类似Scala的case class
``` scheme
(define-case-class person
((name string?)
(age integer?))

(define (%to-string)
(string-append "I am " name " " (number->string age) " years old!"))
(define (%greet x)
(string-append "Hi " x ", " (%to-string))))

(define bob (person "Bob" 21))

(bob :to-string) ; => "I am Bob 21 years old!"
(bob :greet "Alice") ; => "Hi Alice, I am Bob 21 years old!"
```

> **性能警告**:`define-case-class` 通过宏实现,有显著的性能开销。它适合手写代码和原型开发,但**不推荐用于 AI 生成的代码或生产环境部署**。

## 以简为美
金鱼Scheme仍旧遵循和 S7 Scheme 一样的简约的原则。目前,它仅依赖于 [S7 Scheme](https://ccrma.stanford.edu/software/s7/) 、[tbox](https://gitee.com/tboox/tbox) 和 C++98 范围内的标准库。

与 S7 Scheme 类似,[src/goldfish.hpp](src/goldfish.hpp) 和 [src/goldfish.cpp](src/goldfish.cpp) 是构建金鱼Scheme解释器二进制文件所需的唯一关键源代码。

## 标准库
### 类似Scala的集合
| 库 | 描述 |
|------------------------------------------------------------|------------------------------------|
| [(liii rich-char)](tests/goldfish/liii/rich-char-test.scm) | 面向`char`的静态方法和实例方法 |
| [(liii rich-string)](tests/goldfish/liii/rich-string-test.scm) | 面向`string`的静态方法和实例方法 |
| [(liii rich-list)](tests/goldfish/liii/rich-list-test.scm) | 面向`list`的静态方法和实例方法 |
| [(liii rich-vector)](tests/goldfish/liii/rich-vector-test.scm) | 面向`vector`的静态方法和实例方法 |
| [(liii rich-hash-table)](tests/goldfish/liii/rich-hash-table-test.scm) | 面向`hash-table`的静态方法和实例方法 |
| [(liii rich-path)](tests/goldfish/liii/rich-path-test.scm) | 面向`path`的静态方法和实例方法 |

### 类似Python的标准库
形如`(liii xyz)`的是金鱼标准库,模仿Python标准库和Scala集合库的函数接口和实现方式,降低用户的学习成本。
形如`(liii xyz)`的是金鱼标准库,模仿Python标准库的函数接口和实现方式,降低用户的学习成本。

| 库 | 描述 | 示例函数 |
| ------------------------------------------------- | ------------------------------- | ------------------------------------------------------------------ |
| [(liii lang)](goldfish/liii/lang.scm) | 类似Scala的集合库 | `box`支持一致的函数式集合库, `rich-char`和`rich-string`支持Unicode |
| [(liii base)](goldfish/liii/base.scm) | 基础库 | `==`, `!=`, `display*` |
| [(liii error)](goldfish/liii/error.scm) | 提供类似Python的错误函数 | `os-error`函数抛出`'os-error`,类似Python的OSError |
| [(liii check)](goldfish/liii/check.scm) | 基于SRFI 78的轻量级测试库加强版 | `check`, `check-catch` |
Expand All @@ -96,6 +43,8 @@
| [(liii range)](goldfish/liii/range.scm) | 范围库 | `numeric-range`, `iota` |
| [(liii option)](goldfish/liii/option.scm) | Option 类型库 | `option?`, `option-map`, `option-flatten` |
| [(liii uuid)](goldfish/liii/uuid.scm) | UUID 生成 | `uuid4` |
| [(liii http)](goldfish/liii/http.scm) | HTTP 客户端库 | `http-get`, `http-post`, `http-head` |
| [(liii json)](goldfish/liii/json.scm) | JSON 解析和操作 | `string->json`, `json->string` |

### SRFI

Expand Down Expand Up @@ -132,26 +81,6 @@

以下是分步构建和安装指南。

### GNU/Linux
以下是在 Debian bookworm 上构建的命令:
```
sudo apt install xmake git unzip curl g++
git clone https://gitee.com/LiiiLabs/goldfish.git
# git clone https://github.com/LiiiLabs/goldfish.git
cd goldfish
xmake b goldfish
bin/gf --version
```
您也可以将其安装到 `/opt`:
```
sudo xmake i -o /opt/goldfish --root
/opt/goldfish/bin/gf
```
卸载时只需:
```
sudo rm -rf /opt/goldfish
```

### macOS 安装
在 macOS 上,推荐使用 Homebrew 进行安装:
```
Expand Down Expand Up @@ -238,7 +167,7 @@ based on S7 Scheme 11.5 (22-Sep-2025)
`-m` 或 `--mode` 帮助您指定标准库模式:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 liii 模式遗漏 (liii string) 导入(中文版)

与 README.md 相同的问题:customize_goldfish_by_mode 实际上会导入 (liii base)(liii error)(liii string) 三个库,但中文版文档只列出了前两个。

Suggested change
`-m``--mode` 帮助您指定标准库模式:
+ `liii`: 预加载 `(liii base)``(liii error)``(liii string)` 的 Goldfish Scheme


+ `default`: `-m default` 等价于 `-m liii`
+ `liii`: 预加载 `(liii oop)`、`(liii base)` 和 `(liii error)` 的 Goldfish Scheme
+ `liii`: 预加载 `(liii base)` 和 `(liii error)` 的 Goldfish Scheme
+ `scheme`: 预加载 `(liii base)` 和 `(liii error)` 的 Goldfish Scheme
+ `sicp`: 预加载 `(scheme base)` 和 `(srfi sicp)` 的 S7 Scheme
+ `r7rs`: 预加载 `(scheme base)` 的 S7 Scheme
Expand Down
36 changes: 36 additions & 0 deletions devel/200_61.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# [200_61] 更新 README 文档

## 任务相关的代码文件
- README.md
- README_ZH.md

## 2025/04/03

### What

1. 移除基于 Scala 的 data pipeline 相关内容
- 移除 "Scala-like functional collection" 特性描述
- 移除 Functional Data Pipeline 示例代码和图片引用
- 移除 Scala like case class 示例和性能警告

2. 移除 (liii lang) 相关内容
- 移除 Unicode Support 示例(使用 `(liii lang)`
- 从标准库表格中移除 `(liii lang)`
- 移除 "Scala-like collections" 表格

3. 简化安装说明
- 移除 GNU/Linux 安装说明,保留 macOS 安装说明

4. 更新模式选项
- 移除 `(liii oop)` 预加载项
- `liii` 模式现在只预加载 `(liii base)``(liii error)`

5. 新增标准库
- 新增 `(liii http)`:HTTP 客户端库
- 新增 `(liii json)`:JSON 解析和操作库

### Why

由于基于 Scala 的 data pipeline(包括 `(liii lang)`、case class、rich collections 等)已经从代码库中移除,README 文档需要同步更新,以反映当前 Goldfish Scheme 的实际状态,避免误导用户。

同时,新增 `(liii http)``(liii json)` 两个实用库的介绍,帮助用户了解 Goldfish Scheme 的网络和 JSON 处理能力。
27 changes: 21 additions & 6 deletions src/goldfish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4547,9 +4547,16 @@ goldfish_repl (s7_scheme* sc, const string& mode) {
ic_style_def ("symbol", "cyan");

ic_printf ("[b gold]Goldfish Scheme[/] [b plum]%s[/] by LiiiLabs\n"
"[i]Based on S7 Scheme %s [dim](%s)[/][/]\n"
"[b]Mode:[/] [b]%s[/]\n\n",
GOLDFISH_VERSION, S7_VERSION, S7_DATE, mode.c_str ());
"[i]Based on S7 Scheme %s [dim](%s)[/][/]\n",
GOLDFISH_VERSION, S7_VERSION, S7_DATE);
// Display mode info; liii mode shows extra imported libraries
if (mode == "liii" || mode == "default") {
ic_printf ("[b]Mode:[/] [b]%s[/] (additionally imports: (liii base) (liii error) (liii string) compared to r7rs)\n\n",
mode.c_str ());
}
else {
ic_printf ("[b]Mode:[/] [b]%s[/]\n\n", mode.c_str ());
}
ic_printf ("- Type ',quit' or ',q' to quit. (or use [kbd]ctrl-d[/]).\n"
"- Type ',help' for REPL commands help.\n"
"- Press [kbd]F1[/] for help on editing commands.\n"
Expand Down Expand Up @@ -4599,8 +4606,8 @@ struct StartupCliOptions {
};

static std::string
parse_mode_option (int argc, char** argv) {
std::string mode= "default";
parse_mode_option (int argc, char** argv, const std::string& default_mode= "default") {
std::string mode= default_mode;
for (int i= 1; i < argc; ++i) {
string arg= argv[i];
if ((arg == "--mode" || arg == "-m") && (i + 1) < argc) {
Expand Down Expand Up @@ -5107,14 +5114,22 @@ repl_for_community_edition (s7_scheme* sc, int argc, char** argv) {

string command = startup_opts.command;
int command_index= startup_opts.command_index;
string mode = parse_mode_option (argc, argv);

// 如果没有找到命令或没有参数,显示帮助
if (argc <= 1 || command.empty ()) {
display_help ();
return 0;
}

// 根据命令类型确定默认模式:
// - repl/load 命令默认使用 liii 模式
// - 其他命令(eval, run, 直接执行脚本)默认使用 r7rs 模式
string default_mode= "r7rs";
if (command == "repl" || command == "load") {
default_mode= "liii";
}
string mode= parse_mode_option (argc, argv, default_mode);
Comment on lines +5124 to +5131
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 脚本执行默认模式变更为 r7rs 可能破坏现有用户脚本

此更改将 eval/run/直接执行脚本命令的默认模式从 "default"(等价于 liii,会预加载 (liii base) (liii error) (liii string))改为 "r7rs"(仅预加载 (scheme base))。

之前依赖默认模式运行的脚本(如使用 gf run script.scm,脚本内使用了 (liii base) 中的 ==display* 等函数)将无法找到这些绑定,可能在运行时直接报错。

此外,README 中仍描述 default: -m default is the equiv of -m liii,但对于脚本命令,新的实际默认值已是 r7rs,文档与行为不符,需要同步更新。

如这是有意为之的设计决策,建议:

  1. 在 README 中明确记录此行为差异(REPL 和 load 默认使用 liii,脚本执行默认使用 r7rs
  2. 评估是否会对现有用户脚本造成破坏性影响


// 处理旧版的 --help, -h, --version, -v(为了向后兼容)
if (command == "--help" || command == "-h") {
display_help ();
Expand Down
Loading