Felix L. Winkelmann and D.C. Frost
mail to <firstname.lastname@example.org>. See instructions here to subscribe to the list. You can access previous messages via the archive of the mailing list.
This SRFI specifies an extremely simple facility for making an extension or library available to a Scheme toplevel environment.
The (requires ...) clause of SRFI 7 (Feature-based program configuration language) is one possible way for a program to declare that it requires certain features or extensions in order to run. There are two limitations with this facility: first, an implementation of SRFI 7 is not actually required to do anything as the result of encountering a (requires ...) clause. At the time of this writing, some implementations do in fact load and make available the specified extension in this case, but some do not. Second, the SRFI 7 language is most appropriate as an annotation to program text. It is not designed for interactive use.
This SRFI therefore defines a simple mechanism specifically for requiring that extensions be made immediately available to subsequent code at compile-time or runtime, as appropriate. In particular, the intent is that a trivial, portable means exist for loading SRFI functionality within a program or interactive session; but the mechanism described here is general enough to be used for other types of extensions, at the implementation's discretion.
The require-extension form is used to make an extension available in the toplevel scope in which it appears. The definition of a "toplevel scope" and the exact meaning of what it means to make an extension available in one is implementation-defined, but we expect likely scopes will include the default scope in which program expressions are evaluated; the scope in which program expressions within a module are evaluated, as defined by a module system; and the interactive REPL. When require-extension is used to make an extension available in a non-interactive context, it is implementation-defined whether the extension will be available to code lexically preceding the require-extension form in the same scope, but it should be available to code in the same scope lexically succeeding the require-extension form. An implementation should default to signalling a warning or an error in the event that a requested extension cannot be made available.
An implementation claiming to support this SRFI must support require-extension in at least one context.
The syntax of require-extension is as follows:
(require-extension <clause> ...)
A clause has the form:
(<extension-identifier> <extension-argument> ...)
where <extension-identifier> is a symbol and the zero or more <extension-argument>s may be any Scheme values.
This SRFI defines only one extension-identifier, the identifier srfi, which implementations purporting to conform to this SRFI must support. The extension-arguments of an srfi clause may be any Scheme values, at an implementation's discretion, but an implementation must support nonnegative integer extension-arguments and should treat them as a directive to make the functionality of the indicated SRFIs available in the context in which the require-extension form appears. For example:
(require-extension (srfi 1)) ; Make the SRFI 1 List Library available (require-extension (srfi 1 13 14)) ; Make the SRFI 1, 13 and 14 libraries available
The implementation of require-extension is necessarily
Here is a (very simple) example implementation that is based on the optional R5RS load procedure:
;;;; Reference implementation for SRFI-??? ; ; Requirements: SRFI-23 (error reporting) (define available-extensions '()) (define (register-extension id action . compare) (set! available-extensions (cons (list (if (pair? compare) (car compare) equal?) id action) available-extensions)) ) (define (find-extension id) (define (lookup exts) (if (null? exts) (error "extension not found - please contact your vendor" id) (let ((ext (car exts))) (if ((car ext) (cadr ext) id) ((caddr ext)) (lookup (cdr exts)) ) ) ) ) (lookup available-extensions) ) (define-syntax require-extension (syntax-rules (srfi) ((_ "internal" (srfi id ...)) (begin (find-extension '(srfi id) ...)) ) ((_ "internal" id) (find-extension 'id) ) ((_ clause ...) (begin (require-extension "internal" clause) ...)) ) ) ; Example of registering extensions: ; ; (register-extension '(srfi 1) (lambda () (load "/usr/local/lib/scheme/srfi-1.scm")))
This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Scheme Request For Implementation process or editors, except as needed for the purpose of developing SRFIs in which case the procedures for copyrights defined in the SRFI process must be followed, or as required to translate it into languages other than English.
The limited permissions granted above are perpetual and will not be revoked by the authors or their successors or assigns.
This document and the information contained herein is provided on an "AS IS" basis and THE AUTHOR AND THE SRFI EDITORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.