;
; define-opaque.scm
; 0.2
;
; SPDX-FileCopyrightText: In 2023, Chris Pressey, the original author of this work, placed it into the public domain.
; SPDX-License-Identifier: Unlicense
; For more information, please refer to <https://unlicense.org/>
;
(define-syntax opaque-op
(syntax-rules ()
((opaque-op (name body) args)
(apply body args))))
(define-syntax opaque-ops
(syntax-rules ()
((opaque-ops target args ())
(error "Undefined operation:" target))
((opaque-ops target args (op rest ...))
(if (equal? (car 'op) target) (opaque-op op args) (opaque-ops target args (rest ...))))))
(define-syntax define-opaque
(syntax-rules ()
((define-opaque name make-name privs priv-defaults ops)
(define name
(letrec
(
(make-name (lambda privs
(lambda (target . args)
(opaque-ops target args ops))))
)
(make-name . priv-defaults))))))