clojure-write

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Clojure Development Skill

Clojure开发技能

Tool Preference

工具偏好

When
clojure-mcp
tools are available (e.g.,
clojure_eval
,
clojure_edit
), always use them instead of shell commands like
./bin/mage -repl
. The MCP tools provide:
  • Direct REPL integration without shell escaping issues
  • Better error messages and feedback
  • Structural Clojure editing that prevents syntax errors
Only fall back to
./bin/mage
commands when clojure-mcp is not available.
@./../_shared/development-workflow.md @./../_shared/clojure-style-guide.md @./../_shared/clojure-commands.md
clojure-mcp
工具可用时(例如
clojure_eval
clojure_edit
),请始终使用它们,而非
./bin/mage -repl
这类shell命令。MCP工具具备以下优势:
  • 无需处理shell转义问题的直接REPL集成
  • 更完善的错误提示与反馈
  • 可防止语法错误的结构化Clojure编辑功能
仅当clojure-mcp不可用时,才退而使用
./bin/mage
命令。
@./../_shared/development-workflow.md @./../_shared/clojure-style-guide.md @./../_shared/clojure-commands.md

REPL-Driven Development Workflow

REPL驱动的开发工作流

  • Start with small, fundamental functions:
  • Identify the core features or functionalities required for your task.
  • Break each feature down into the smallest, most basic functions that can be developed and tested independently.
  • Write and test in the REPL:
    • Write the code for each small function directly in the REPL (Read-Eval-Print Loop).
    • Test it thoroughly with a variety of inputs, including typical use cases and relevant edge cases, to ensure it behaves as expected.
  • Integrate into source code:
    • Once a function works correctly in the REPL, move it from the REPL environment into your source code files (e.g., within appropriate namespaces).
  • Gradually increase complexity:
    • Build upon tested, basic functions to create more complex functions or components.
    • Compose smaller functions together, testing each new composition in the REPL to verify correctness step by step.
  • Ensure dependency testing:
    • Make sure every function is fully tested in the REPL before it is depended upon by other functions.
    • This ensures that each layer of your application is reliable before you build on it.
  • Use the REPL fully:
    • Use the REPL as your primary tool to experiment with different approaches, iterate quickly, and get immediate feedback on your code.
  • Follow functional programming principles:
    • Keep functions small, focused, and composable.
    • Use Clojure's functional programming features—like immutability, higher-order functions, and the standard library—to write concise, effective code.
  • 从小型基础函数入手:
  • 明确任务所需的核心特性或功能。
  • 将每个特性拆解为可独立开发和测试的最小粒度基础函数。
  • 在REPL中编写并测试:
    • 直接在REPL(读取-求值-打印循环)中编写每个小型函数的代码。
    • 使用各种输入(包括典型用例和相关边缘情况)进行全面测试,确保其行为符合预期。
  • 集成到源代码中:
    • 当函数在REPL中运行正常后,将其从REPL环境迁移到源代码文件中(例如放入合适的命名空间)。
  • 逐步提升复杂度:
    • 基于已测试的基础函数构建更复杂的函数或组件。
    • 将小型函数组合在一起,每次新组合都在REPL中测试,逐步验证正确性。
  • 确保依赖测试:
    • 确保每个函数在被其他函数依赖前,已在REPL中完成全面测试。
    • 这能保证在构建应用的上层逻辑前,每一层都是可靠的。
  • 充分利用REPL:
    • 将REPL作为主要工具,尝试不同方法、快速迭代并获取代码的即时反馈。
  • 遵循函数式编程原则:
    • 保持函数小巧、聚焦且可组合。
    • 利用Clojure的函数式编程特性——如不可变性、高阶函数和标准库——编写简洁高效的代码。

How to Evaluate Code

代码评估方法

Bottom-up Dev Loop

自底向上开发循环

  1. Write code into a file.
  2. Evaluate the file's namespace and make sure it loads correctly with:
./bin/mage -repl --namespace metabase.app-db.connection
  1. Call functions in the namespace with test inputs, and observe that the outputs are correct Feel free to copy these REPL session trials into actual test cases using
    deftest
    and
    is
    .
  2. Once you know these functions are good, return to 1, and compose them into the task that you need to build.
  1. 将代码写入文件。
  2. 评估文件的命名空间,确保通过以下命令能正确加载:
./bin/mage -repl --namespace metabase.app-db.connection
  1. 使用测试输入调用命名空间中的函数,观察输出是否正确 你可以将这些REPL会话中的测试用例复制出来,使用
    deftest
    is
    转化为正式测试用例。
  2. 确认这些函数没问题后,回到步骤1,将它们组合成你需要构建的任务。

Critical Rules for Editing

编辑的关键规则

  • Be careful with parentheses counts when editing Clojure code
  • After EVERY change to Clojure code, verify readability with
    -check-readable
  • End all files with a newline
  • When editing tabular code, where the columns line up, try to keep them aligned
  • Spaces on a line with nothing after it is not allowed
  • 编辑Clojure代码时注意括号的数量
  • 每次修改Clojure代码后,使用
    -check-readable
    验证可读性
  • 所有文件末尾必须换行
  • 编辑列对齐的表格型代码时,尽量保持对齐
  • 不允许存在只有空格的空行