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