implement-primitive
A guide for implementing new JavaScript primitives and exposing them to Scheme.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
A guide for implementing new JavaScript primitives and exposing them to Scheme.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | Implement Primitive |
| description | A guide for implementing new JavaScript primitives and exposing them to Scheme. |
This skill guides you through adding a new JavaScript primitive to the Scheme interpreter. Primitives are JavaScript functions exposed to Scheme, typically used for:
[!IMPORTANT] Scheme over JS: Only implement primitives when necessary. If logic can be implemented in Scheme (even if it's slower initially), prefer Scheme. Use primitives for things Scheme cannot do (IO, direct JS interop).
src/core/primitives/.src/extras/primitives/.Create a new file or update an existing one in src/extras/primitives/ (e.g., feature.js).
Pattern:
import { ... } from '../../core/interpreter/type_check.js'; // conversions/assertions
import { schemePrimitives } from '../../core/interpreter/scheme_primitives.js'; // if wrapping scheme
export const myPrimitives = {
'scheme-name': (arg1, arg2) => {
// 1. assertions
// 2. logic
return result;
}
}
// OR if you need the interpreter instance (e.g. for creating closures/promises)
export function getMyPrimitives(interpreter) {
return {
'scheme-name': (arg1) => { ... }
}
}
assertString, assertProcedure) from type_check.js.SchemeError or specific subclasses.Update src/core/primitives/index.js to import and register your primitives.
import { myPrimitives } from '../../extras/primitives/feature.js';
// ... inside createGlobalEnvironment
addPrimitives(myPrimitives);
Create a .sld file in src/extras/scheme/ (e.g., feature.sld) to export the new primitives.
(define-library (scheme-js feature)
(export scheme-name ...)
(import (scheme base)) ;; or others
;; The primitives are already in the global environment via index.js,
;; so we usually just export them.
;; Sometimes we might re-export or wrap them.
)
Note: In this project's architecture, primitives added to createGlobalEnvironment are available globally, but for R7RS compliance and cleanliness, we wrap them in a library.
tests/ (usually tests/extras/primitives/ or similar).node run_tests_node.jshttp://localhost:8080/ui.html基于 SOC 职业分类
A guide for updating project documentation (CHANGES.md, Roadmap, etc.).
A guide for creating new Scheme libraries (R7RS) in the project.
Guidelines for moving logic from JavaScript to Scheme (Schemification).