← 返回 Skill 列表
extension
分类: 开发与工程API Key 暂未确认

clojure

使用deps.edn、tools.deps和函数式模式开发Clojure应用程序。在处理.clj/.cljc/.cljs文件、deps.edn,或用户提到Clojure、REPL、spec、transducers、reducers或函数式编程时激活。

person作者: jakexiaohubgithub

Clojure Development

Focus: functional Clojure; deps.edn, tools.deps, immutability.

Workflow

1. MODEL    -> Define data with maps, records, specs
2. COMPOSE  -> Build with pure functions, ->> threading
3. TEST     -> Write tests first (clojure.test or Kaocha)
4. VALIDATE -> clojure -M:test/run && clj-kondo --lint src
5. ITERATE  -> Refactor in REPL, keep functions pure

CLI

# Project setup
clojure -Tnew app :name myuser/myapp    # New app project
clojure -Tnew lib :name myuser/mylib    # New library

# Run
clojure -M -m myapp.core                # Run -main
clojure -M:run                          # Via alias
clojure -X:run                          # Exec function

# REPL
clj                                     # Basic REPL
clojure -M:repl/rebel                   # Rebel readline

# Test
clojure -X:test/run                     # Run tests (Kaocha)
clojure -M:test -m kaocha.runner        # Alternative

# Build
clojure -T:build uber                   # Uberjar
clojure -T:build jar                    # Library jar

# Dependencies
clojure -X:deps tree                    # Dependency tree
clojure -X:deps find-versions :lib clojure.java-time/clojure.java-time
clojure -M:search/outdated              # Find outdated deps

Notes

Project layout, deps.edn templates, core patterns, naming conventions, anti-patterns: reference.md.

Engineering checks

  • Normalize untrusted input once at the boundary; use clojure.spec only when validation or generation pays for itself.
  • Preserve error context with ex-info and structured ex-data; NEVER catch-and-forget failures.
  • Keep side effects, resource ownership, cancellation, and cleanup at the edge; keep core transformations pure.
  • Test observable behavior and failure paths with deterministic values; avoid pinning private implementation shape.
  • Introduce helpers, protocols, or abstractions only for concrete reuse or boundary needs.

Research Tools

# gh search code for real-world Clojure patterns
gh search code "(go-loop [" --language=clojure
gh search code "(comp (map" --language=clojure
gh search code "(s/def ::" --language=clojure

Required follow-up reads

|Need|Read|When| |---|---|---| |Core language/project reference|reference.md|For data structures, idioms, errors, layout, or deps.edn| |Functional patterns|cookbook/patterns.md|For sequences, transducers, maps, reducers, or zippers| |Concurrency|cookbook/concurrency.md|For atoms, refs, agents, dynamic vars, core.async, futures, or promises| |Specs|cookbook/spec.md|For validation, conforming, generators, or function instrumentation| |Testing|cookbook/testing.md|For clojure.test, Kaocha, fixtures, async tests, or test.check| |Macros|cookbook/macros.md|Only when a function cannot express the required compile-time transformation|