Amber-Lang 0.6.0 - New release, check what's new
Amber-Lang 0.6.0 - New release, check what’s new
What’s new
Amber 0.6.0 brings exciting new features, improved developer experience, multi-shell support, and important additions to the standard library. Let’s delve into what’s new.
新特性概览
Amber 0.6.0 带来了令人兴奋的新功能、改进的开发者体验、多 Shell 支持以及标准库的重要更新。让我们深入了解一下有哪些新变化。
Multi-shell support (Zsh, Ksh, Bash 3.2)
Amber now supports compiling not just to modern Bash, but also directly to Zsh, Ksh, and Bash 3.2 via the new --target argument! Now you can deploy Amber scripts in a broader range of UNIX environments.
amber my_script.ab --target zsh
Amber generated scripts now emit the correct shebang for the selected target. Range-related generated code no longer depends on external bc/sed in the same way, greatly improving portability, especially on macOS (where Bash 3.2 is default). You can also now use the new shellname() and shellversion() builtins for runtime shell introspection.
echo("Running on {shellname()} version {shellversion()}")
多 Shell 支持 (Zsh, Ksh, Bash 3.2)
Amber 现在不仅支持编译为现代 Bash,还可以通过新的 --target 参数直接编译为 Zsh、Ksh 和 Bash 3.2!现在,你可以在更广泛的 UNIX 环境中部署 Amber 脚本。
amber my_script.ab --target zsh
Amber 生成的脚本现在会为所选目标输出正确的 Shebang。与范围相关的生成代码不再以同样的方式依赖外部的 bc/sed,这极大地提高了可移植性,特别是在 macOS(默认使用 Bash 3.2)上。你现在还可以使用新的 shellname() 和 shellversion() 内置函数进行运行时 Shell 自省。
echo("Running on {shellname()} version {shellversion()}")
Public (pub) variables
You can now declare variables as pub to expose them across modules, simplifying data sharing across your multi-file Amber projects.
pub const my_global = "value"
Please note that exposing mutable variables (pub let) is also supported but requires explicit opt-in using the #[allow_public_mutable] attribute at declaration.
公共 (pub) 变量
你现在可以将变量声明为 pub 以在模块间公开它们,从而简化多文件 Amber 项目中的数据共享。
pub const my_global = "value"
请注意,公开可变变量 (pub let) 也是支持的,但需要在声明时使用 #[allow_public_mutable] 属性显式开启。
Recursive Functions
Amber now supports recursive function calls, giving you more flexibility for implementing algorithms.
fun factorial(n: Int): Int {
if n <= 1 { return 1 }
return n * factorial(n - 1)
}
echo("{factorial(4)}") // Outputs: 24
递归函数
Amber 现在支持递归函数调用,为你实现算法提供了更大的灵活性。
fun factorial(n: Int): Int {
if n <= 1 { return 1 }
return n * factorial(n - 1)
}
echo("{factorial(4)}") // 输出: 24
Ternary Control-Flow Validation
Added control-flow-aware validation for ternary expressions and related typing, making your inline conditional assignments much safer and smarter.
let result = value is Num then 42 else "Hello World"
三元控制流验证
为三元表达式及相关类型增加了控制流感知验证,使你的内联条件赋值更加安全和智能。
let result = value is Num then 42 else "Hello World"
Union Types
Union types provide a flexible way to define function parameters that can accept values of multiple distinct types.
fun print_value(val: Int | Text | Bool) {
echo(val)
}
联合类型
联合类型提供了一种灵活的方式来定义函数参数,使其能够接受多种不同类型的值。
fun print_value(val: Int | Text | Bool) {
echo(val)
}
Testing suite
Amber now features a built-in testing suite. It allows you to write dedicated test blocks that are only executed when running the amber test command. We also introduced a new std/test library.
test "can multiply numbers" { let result = 10 * 2 // assertions ... }
测试套件
Amber 现在内置了测试套件。它允许你编写专门的测试块,这些测试块仅在运行 amber test 命令时执行。我们还引入了新的 std/test 库。
test "can multiply numbers" { let result = 10 * 2 // 断言 ... }
Improved variable diagnostics
The compiler now surfaces clearer warnings when variables are not used, helping you catch mistakes earlier. It also warns when a variable declared with let is never modified, encouraging the use of const for bindings that never need reassignment. All same-scope redeclarations of symbols are now completely rejected, enforcing better coding practices.
改进的变量诊断
编译器现在会在变量未被使用时给出更清晰的警告,帮助你更早地发现错误。当使用 let 声明的变量从未被修改时,它也会发出警告,鼓励对无需重新赋值的绑定使用 const。现在,同一作用域内的所有符号重复声明都将被完全拒绝,从而强制执行更好的编码实践。
Enhanced CLI and Failable diagnostics
Improved handling and messaging for unknown CLI commands, including typo suggestions to quickly help you fix your command. It also brings improved errors when external commands do not exist. Rules around failable functions are also now strictly validated.
增强的 CLI 和可失败函数诊断
改进了对未知 CLI 命令的处理和提示信息,包括拼写错误建议,以快速帮助你修正命令。当外部命令不存在时,它也提供了改进的错误提示。关于可失败函数(Failable functions)的规则现在也得到了严格验证。
Improved runtime safety
A runtime error is now raised correctly if you attempt out-of-bounds indexing on arrays, including source location.
let items = ["apple", "banana"]; echo(items[5]) // Error: Index out of bounds
改进的运行时安全
如果你尝试对数组进行越界索引,现在会正确引发运行时错误,并包含源代码位置信息。
let items = ["apple", "banana"]; echo(items[5]) // 错误:索引越界
New builtins and syntax reform
All builtins like echo have moved toward function-call syntax with parentheses. Older no-parentheses builtin calls are still supported in relevant cases, but now emit deprecation warnings. Amber has gained many new builtins for common shell operations (e.g., touch, rm, sleep, ls, pwd, clear, cp, pid, disown, lock, await, shellname, shellversion, suppress).
新内置函数与语法改革
所有像 echo 这样的内置函数都已转向使用带括号的函数调用语法。旧的无括号内置调用在相关情况下仍然支持,但现在会发出弃用警告。Amber 增加了许多用于常见 Shell 操作的新内置函数(例如 touch、rm、sleep、ls、pwd、clear、cp、pid、disown、lock、await、shellname、shellversion、suppress)。