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 페이지를 검토하고 설치를 진행할 수 있습니다.
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).
| 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