dynamic-import
Documentation
A dynamic import facility for CHICKEN Scheme.
Usage
(import dynamic-import)Note strongly suggest warnings be disabled before using dynamic-import: (enable-warnings #f).
"Warning: imported identifier doesn't exist in module ..." can occur due to missing exported identifiers during module search. Also, warnings from dynamic-import flow thru a different channel.
dynamic-import
Attempts to import the identifiers ID ... from a module, in the listed module MD ... order. Should no module succeed, the default specification DEF is used to bind the identifiers.
The extend module identifier syntax, ex: (srfi 1) & (main sub1 sub1-1), is supported. However, use does need to be as ((srfi 1) (main sub1 sub1-1)), to prevent misunderstanding.
MD;(or symbol (list symbol fixnum) (list-of (or symbol number)))ID;(symbol)DEF(default * ...); literal default is(* ...)DEFprocedure; default is the result of(DEF IDs)
The IDs are assigned from the default list, w/ an element for each ID.
dynamic-import-warning
(dynamic-import-warning [WARN]) -> procedure: WARN ; (#!rest -> void) ; warning procedure; default warning
dynamic-importer
(dynamic-importer MDS IDS [DEFAULT]) -> (or false list)Performs runtime import.
MDS- see dynamic-import
IDS- see dynamic-import
DEFAULT(or false list (import-names -> (or false list)))
Dynamic Plugin
Usage
(import dynamic-plugin)import-plugin
(import-plugin MDS IDS) -> (or false list)Performs runtime import. Returns a list of the imports or #f.
Arguments MDS & IDS are like those of dynamic-importer but allow an atomic form.
import-plugin-option
(import-plugin-option MDS IDS) -> (or false list)Performs runtime import. Returns a list of the imports or #f.
Arguments MDS & IDS are like those of dynamic-importer but add string & allow an atomic form.
The addition of string is of dubious utility.
Examples
;;;; preferred list of TCP implementations
(import dynamic-import)
(parameterize ((enable-warnings #f) ;see note in documentation above
(dynamic-import-warning void))
; tcp-listen ... from tcp6 else (chicken tcp) else stub
;
; default is procedure and called unlike the example below
;
(dynamic-import (tcp6 (chicken tcp))
(tcp-listen tcp-listener-fileno tcp-listener-port
tcp-accept tcp-accept-ready? tcp-close
tcp-abandon-port tcp-buffer-size tcp-connect
tcp-read-timeout tcp-write-timeout)
; make, named, failure defaults for the imports
(lambda (ids) (map (lambda (id) (lambda _ (error id "no dynamic import"))) ids)))
;
; NOTE on import failure: (tcp-read-timeout ...)
; => Error: (tcp-read-timeout) no such import
; ssl-connect* from openssl else stub
;
; default is literal, a procedure but not called as above.
;
; only one import so only one default; one per import.
(dynamic-import openssl ssl-connect* (default (lambda _ (values #f #f))))
;
; NOTE on import failure: (ssl-connect* ...)
; => #f #f
)Bugs & Limitations
- Very not portable Scheme.
- The toplevel is polluted due to lack of lexical scope.
Notes
- Inspired by Feb 12 '22 #chicken irc discussion.
Requirements
- Test dependencies only
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/dynamic-import
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Version history
- 1.6.0
- Add
import-plugin - 1.5.1
- Fix
dynamic-pluginsignature. - 1.5.0
- Add
dynamic-plugin - 1.4.2
- Default
#fvalid. - 1.4.1
- Restrict import defaults.
- 1.4.1
- Expose
dynamic-importer. - 1.3.0
- CHICKEN 6 Release.
License
This code is in the public domain.