lib/guest/prefix.sx defines a single (defmacro prefix-rename PREFIX ENTRIES) form that takes a prefix string and a quoted list of entries. Each entry is either a bare symbol (same-name alias: cl-foo = foo) or a 2-element list (alias target) for renames (cl-mod = modulo). Ported lib/common-lisp/runtime.sx: 47 hand-written (define cl-X Y) lines across 13 contiguous groups now collapse into prefix-rename calls. Loaded lib/guest/prefix.sx in the conformance preamble so the macro is available when runtime.sx is parsed. Verification: cl scoreboard 518/518, up from a stale baseline of 309/309 — Phase 2 (evaluator, +182) and Phase 6 (stdlib, +27) had under-counted historical results, not affected by this change. No regressions; baseline updated to reflect true counts. PARTIAL — pending second consumer. lua/runtime.sx (the brief's specified second consumer) has zero pure same-name aliases — every lua- definition wraps custom logic. Step left [partial — pending lua] until a consumer fits, or the second-consumer choice is revisited (js/runtime.sx has 2 candidates: isFinite/isNaN). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.5 KiB
Plaintext
47 lines
1.5 KiB
Plaintext
;; lib/guest/prefix.sx — prefix-rename macro.
|
|
;;
|
|
;; A guest runtime often re-exports a stretch of host primitives under a
|
|
;; language-specific prefix. The prefix-rename macro replaces the repeated
|
|
;; (define lang-foo foo) boilerplate with a single declarative call.
|
|
;;
|
|
;; Two entry shapes are supported:
|
|
;;
|
|
;; (prefix-rename "cl-" '(gcd lcm expt floor truncate))
|
|
;; ;; expands to (begin (define cl-gcd gcd)
|
|
;; ;; (define cl-lcm lcm) ...)
|
|
;;
|
|
;; (prefix-rename "cl-"
|
|
;; '((mod modulo)
|
|
;; (arrayp? vector?)
|
|
;; (ceiling ceil)))
|
|
;; ;; expands to (begin (define cl-mod modulo)
|
|
;; ;; (define cl-arrayp? vector?)
|
|
;; ;; (define cl-ceiling ceil))
|
|
;;
|
|
;; Mixed lists are supported — bare symbols are same-name aliases, two-element
|
|
;; lists are (alias target) pairs.
|
|
|
|
(defmacro
|
|
prefix-rename
|
|
(prefix entries-q)
|
|
(let
|
|
((entries (nth entries-q 1)))
|
|
(cons
|
|
(quote begin)
|
|
(map
|
|
(fn
|
|
(entry)
|
|
(cond
|
|
((= (type-of entry) "symbol")
|
|
(list
|
|
(quote define)
|
|
(make-symbol (str prefix (symbol-name entry)))
|
|
entry))
|
|
((and (list? entry) (= (len entry) 2))
|
|
(list
|
|
(quote define)
|
|
(make-symbol (str prefix (symbol-name (first entry))))
|
|
(nth entry 1)))
|
|
(:else (error (str "prefix-rename: invalid entry " entry)))))
|
|
entries))))
|