这里是 Scoop 编程语言的官网。如果你在找 Windows 命令行包管理器 Scoop,请访问 scoop.sh。
This is the home of the Scoop programming language. Looking for the Scoop package manager for Windows? Visit scoop.sh.
熟悉的语法,
原生的性能。
Scoop 是一门静态类型、编译到原生代码的编程语言。它以 Kotlin 的核心语法为基础,加入真正的值类型(struct / enum / tuple)与模式匹配,泛型采用单态化,经 LLVM 生成机器码,并由带分代 Immix GC 的 C 运行时托管内存。工具链自带声明式的原生桌面 UI 框架,同一份代码运行在 macOS、Linux 与 Windows 上。
struct Point(val x: Int, val y: Int)
enum Shape {
Circle(Point, Int),
Line(Point, Point)
}
fun describe(shape: Shape): String = when (shape) {
case Circle(Point(0, 0), val r) -> f"circle at origin, r=${r}"
case Circle(val center, _) -> f"circle at ${center.x},${center.y}"
case Line(val from, val to) -> f"line of dx=${to.x - from.x}"
}
fun main() {
val origin = Point(0, 0)
val moved = origin.{ x: 5 }
println(describe(Shape.Circle(origin, 3)))
println(describe(Shape.Line(origin, moved)))
}为什么选择 Scoop
保留 Kotlin 优雅、表达力强的写法,去掉平台包袱,换来可预测的内存布局与原生二进制。
真正的值类型
struct、带载荷的 enum 和 tuple 都是不可变、无 identity 的值,内联存储、按值复制,数组中连续排布,不再为小对象付出堆分配的代价。
强大的模式匹配
when 支持 enum 变体、tuple、struct 的嵌套解构、guard 与穷尽性检查,未覆盖的情况在编译期给出可读的反例。
没有 null
T? 是 Option<T> 的语法糖,?.、?:、!! 照常可用;T?? 与 T? 是不同类型,语义精确。
单态化泛型 + LLVM
每组具体类型实参生成专门代码,避免类型擦除带来的装箱;LLVM 后端完成优化并支持跨 Cone 内联。值转换为接口或 Any 时仍按语言规则装箱。
精确移动 GC
C 运行时提供精确根、写屏障与分代 Immix 收集;原生资源通过 close、use 或 useAsync 确定性关闭,release 块提供尽力而为的回收清理。
直接的 C FFI
@Extern 绑定 C 函数和全局变量,@CLayout、Ptr<T>、FunPtr<F> 描述原生内存,@Unsafe 明确标出不安全边界。
写起来是这样的
以下每段代码都用当前工具链实际编译运行过。
fun main() {
println("Hello, Scoop!")
}$ scoop run hello.scoop --release
Hello, Scoop!struct Point(val x: Int, val y: Int) : ToString {
fun dist2(): Int = x * x + y * y
public override fun toString(): String = f"(${x}, ${y})"
}
struct Config(val host: String, val port: Int = 8080, val debug: Boolean = false)
fun main() {
val p = Point(3, 4)
val q = p.{ y: 10 }
println(f"p=${p} q=${q} |p|^2=${p.dist2()}")
println(p == Point(3, 4))
val (x, y) = p
println(x + y)
val config = Config("localhost", debug = true)
val Config { host, port, .. } = config
println(f"${host}:${port}")
val pair = (1, "one")
val (num, word) = pair
println(f"${num} -> ${word}, ${pair._2}")
}struct User(val name: String, val email: String?)
fun find(users: Array<User>, name: String): User? {
for (u in users) {
if (u.name == name) return Some(u)
}
return None
}
fun main() {
val users = [User("ada", Some("[email protected]")), User("lin", None)]
// `?.` does not flatten: the result is Option<Option<String>>
val email: String?? = find(users, "ada")?.email
println(email == Some(Some("[email protected]")))
val domain: String = when (val e = find(users, "lin")) {
case Some(User { email: Some(val addr), .. }) -> addr
case Some(_) -> "no email"
case None -> "no user"
}
println(domain)
println(find(users, "bob")?.name ?: "anonymous")
val nested: Int?? = Some(None)
println(nested == None)
}//! dep: scoop:scoop.json:0.1.0
import scoop.json.*
struct User(val name: String, val scores: Array<Int>, val note: String? = None) {
@GenerateWith("scoop.codec", ["ValueEncoder<User>", "ValueDecoder<User>"])
public companion object: ValueEncoder<User>, ValueDecoder<User>
}
fun main() {
val original = User("Ada", [7, 9])
val text = Json.encodeToString(original)
println(text)
val decoded = Json.decodeFromString<User>(text)
println(f"${decoded.name}: ${decoded.scores[1L]}")
println(decoded.note ?: "no note")
}//! dep: scoop:scoop.asyncio:0.1.0
//! dep: scoop:scoop.http.server:0.1.0
import scoop.asyncio.*
import scoop.http.server.*
private struct GreetingQuery(val name: String = "world") {
@GenerateWith("scoop.codec", ["ValueDecoder<GreetingQuery>"])
public companion object: ValueDecoder<GreetingQuery>
}
private struct GreetingInput(val name: String) {
@GenerateWith("scoop.codec", ["ValueDecoder<GreetingInput>"])
public companion object: ValueDecoder<GreetingInput>
}
private struct GreetingOutput(val message: String) {
@GenerateWith("scoop.codec", ["ValueEncoder<GreetingOutput>"])
public companion object: ValueEncoder<GreetingOutput>
}
fun main() {
val loop = eventLoop()
loop.run suspend {
HttpServer.listen(this) {
get(
"/greet",
suspend {
ctx ->
val query = ctx.request.query.decode<GreetingQuery>()
json(GreetingOutput("Hello, " + query.name + "!"))
}
)
post(
"/greet",
suspend {
ctx ->
val input = ctx.request.body.json<GreetingInput>()
json(GreetingOutput("Hello, " + input.name + "!"))
}
)
}.useAsync suspend {
server ->
println("Listening at http://" + server.localAddress.toString())
server.awaitTermination()
}
}
}# Terminal 1
$ scoop run --release http_server.scoop
# Terminal 2
$ curl 'http://127.0.0.1:8080/greet?name=Scoop'
{"message":"Hello, Scoop!"}//! dep: scoop:scoop.graphics:0.1.0
//! dep: scoop:scoop.graphics.text:0.1.0
//! dep: scoop:scoop.ui:0.1.0
//! dep: scoop:scoop.ui.component:0.1.0
//! dep: scoop:scoop.ui.style:0.1.0
//! dep: scoop:scoop.ui.style.shadcn:0.1.0
import scoop.graphics.Paint
import scoop.graphics.text.TextAlignment
import scoop.ui.*
import scoop.ui.component.*
import scoop.ui.style.ThemeMode
import scoop.ui.style.ThemeSource
import scoop.ui.style.currentThemeSource
import scoop.ui.style.read
import scoop.ui.style.shadcn.shadcnTheme
class Counter(scope: ComponentScope): Component(scope) {
// Captured once at construction; the mount factory runs inside context(source).
private val theme = currentThemeSource()
private val count = state(0)
public override fun render(): View {
val count = this.count
val content =
column {
spacing = 16.0
alignment = CrossAlignment.Center
// Text fills the bounded width, so center the paragraph itself.
typography("Counter", TypographyRole.H3) {
settings { alignment = TextAlignment.Center }
}
label(f"Clicked ${count.value} times") {
settings { alignment = TextAlignment.Center }
}
row {
spacing = 8.0
button("-1", { count.value -= 1 }) {
variant = ButtonVariant.Outline
enabled = count.value > 0
}
button("+1", { count.value += 1 })
button("Reset", { count.value = 0 }) { variant = ButtonVariant.Ghost }
}
}
// Read the theme with this window's display preferences.
val pageColor = this.theme.read(scope).tokens.palette.background.background
return frame(content) { style { background(Some(Paint(pageColor))) } }
}
}
fun main() {
val source = ThemeSource(shadcnTheme(ThemeMode.Light))
context(source) {
runUiApplication("Counter", { scope -> Counter(scope) })
}
}$ scoop run --release ui-counter-layout.scoop
# 打开一个窗口:标题 Counter、点击次数和 -1 / +1 / Reset 三个按钮package examples.testing
import scoop.test.*
@Test
private class CalculatorTests {
@Test
fun `division returns a value`() {
assertEquals(6, divide(42, 7))
assertTrue(divide(42, 7) > 0)
}
@Test
fun `zero count reports the reason`() {
val error = assertFailsWith<IllegalArgumentException> { divide(42, 0) }
assertEquals(Some("count must not be zero"), error.message)
}
}$ scoop test --release
assertions
examples.testing.CalculatorTests [passed]
division returns a value (tests/calculator.scoop:7:5) passed (2000 ns)
zero count reports the reason (tests/calculator.scoop:13:5) passed (91000 ns)
1 containers, 2 tests: 2 passed, 0 failed, 0 ignored, 0 not run原生桌面 UI
随工具链发布的声明式 UI 框架:保留身份的组件、细粒度状态与四套主题,界面由 Skia 自绘,窗口、菜单与托盘使用系统原生实现。
- 组件即 class:
render()返回不可变的 View,成员State被写入时只重绘依赖它的组件,模型与 SwiftUI、Jetpack Compose 相近。 - 开箱的控件库:按钮、输入框、选择器、表单校验、滚动与虚拟列表、Popover、Dialog、菜单、Toast、Tabs、表格、多列树、日历与图表。
- 控件支持触摸、手势与无障碍。除了轻点、长按和拖动,自绘内容还可以响应捏合与旋转。键盘和系统读屏器也能操作同一组控件。见手势翻页示例。
- 四套主题预设:macOS、Material、Fluent 与 shadcn,支持浅色、深色与跟随系统,可定制 tokens 与局部样式。
- 完整的桌面集成:多窗口、原生菜单与窗框、文件对话框、Dock/任务栏、系统托盘,后台任务与 UI 线程协同。
- 可测试、可分发:状态测试与窗口测试由
scoop test运行,scoop bundle打包为 macOS app、deb/rpm/AppImage 或 NSIS/MSI。
macOS(Metal)· Linux GNU(Wayland / X11,EGL)· Windows(D3D12)
开箱即用的工具链
一个 scoop 命令覆盖新建、包管理、构建、运行、测试、格式化、检查、文档生成与应用打包。
新建 Cone
生成可执行或库模板,附带示例测试。
依赖与工作区
解析版本要求,获取 Git 与 registry 源码,用 Cone.lock 固定选择。
单文件即跑
直接运行 .scoop 文件,用 //! dep: 声明依赖。
内建测试
@Test 标注、断言库与生命周期钩子。
API 文档
从文档注释生成离线、可搜索的文档站点。
构建产物
生成可执行文件或 .slib 库,可用 --emit 导出 AST/HIR/MIR/LIR。
格式化与检查
参照 Kotlin 编码约定统一源码格式,完成前端检查;支持检查测试源码。
离线示例
按主题或关键词查找完整程序、运行步骤与预期结果。
原生调试
断点、变量、源码行与异常物理栈;可调试应用和 Cone 测试。
应用打包
生成 macOS app、deb/rpm/AppImage 与 NSIS/MSI 安装包,统一部署资源和原生库。
语言服务
诊断、补全、跳转、类型与调用层级、重命名、提取与内联等重构;VS Code 扩展提供 Tree-sitter 高亮。
增量与缓存
预编译库产物,输入未变化时直接复用。
功能完整的标准库
四十多个随工具链发布的预编译库 Cone,从集合、文本、TLS 与 HTTP/2 到 2D 绘图与桌面 UI。
核心与基础库
集合、文本、字节、日期时间、UUID。
scoop.asyncio异步 I/O
eventLoop() 在 macOS 使用 libdispatch,在 Linux 使用 io_uring,在 Windows 使用 IOCP;scoop.concurrent 提供多线程执行器与 channel。
HTTP 客户端与服务端
HTTP/1.1、HTTP/2、SSE、WebSocket。
scoop.json数据与编码
JSON、正则、URL、字符集、压缩。
scoop.tls / crypto安全
基于 OpenSSL 的 TLS、摘要与 HMAC。
scoop.math数学
标量数学、BigInteger、BigDecimal。
scoop.cli / log应用开发
声明式命令行解析、日志 facade。
scoop.terminal终端
ANSI 样式、按键事件、readline。
scoop.ui.*声明式 UI
组件与状态框架、基础控件库,macOS/Material/Fluent/shadcn 主题。
scoop.graphics2D 图形
基于 Skia 的绘图、SkSL 着色器、SVG 与段落排版,可离屏渲染。
scoop.window窗口与呈现
原生窗口、全屏、事件与菜单,帧调度、动画与区域输入。
scoop.desktop / tray桌面集成
Dock 与任务栏状态、Jump List、系统托盘、Lucide 图标。
动手试试
一行命令安装工具链:
curl -fsSL https://scoop-lang.org/install.sh | shirm https://scoop-lang.org/install.ps1 | iex