deferred
0.9.0A simple library allowing you to write code using deferred libraries.
Table of Contents
About Deferred
Sometimes I would like to include code in my project that is only available if certain libraries are loaded. Since I don't want to require these libraries as dependencies, but can't refer to their symbols either without them being loaded, things get a bit messy. This library attempts to provide a much more convenient way.
How To
Deferred uses two components: a dispatch reader macro on #^
and two macros, WITH-DEFERRED-LIBRARY
or WHEN-PACKAGES
. #^
is used to circumvent the reader problem of being unable to refer to symbols in packages that don't exist at read-time. The macro is used to then acquire access to the symbol's environment to figure out the proper transformation for the symbol into proper values.
WITH-DEFERRED-LIBRARY
is used to specify deferred libraries that are needed at execution time. Meaning the required library can be loaded only just when the code block is executed.
(with-deferred-library (:drakma)
(#^http-request "http://google.com"))
Deferred symbols can be used in function calls, with FUNCTION
and QUOTE
and as values (f.e. special variables). Currently unsupported are deferred SETF
functions as it's impossible to properly defer a SETF
-expander until execution-time.
If instead you are looking for code that is only compiled when certain libraries are already loaded before yours, there is WHEN-PACKAGES
. This macro only outputs code when the specified list of packages can be found, otherwise it expands to NIL. This is useful if you don't want to encounter the edge-cases and performance penalties of WITH-DEFERRED-LIBRARY
and can depend on the fact that if the deferred feature is needed, its dependencies are loaded before your system.
(defun frillneckedlizard ()
(error "NOT IMPLEMENTED!"))
(when-packages (:drakma)
(defun frillneckedlizard ()
(#^drakma:http-request "http://frillneckedlizard.moe")))
If the default dispatch reader macro has been overwritten in your readtable for one reason or another, you can use (named-readtables:in-readtable :deferred)
.
System Information
Definition Index
-
DEFERRED
- ORG.TYMOONNEXT.DEFERRED
No documentation provided.-
EXTERNAL SPECIAL-VARIABLE *DEFERRED-PACKAGE*
The default package to use for deferred symbols.
-
EXTERNAL GENERIC-FUNCTION PROCESS
- THING
- &REST
Processes THING to transform all deferred symbols within into their proper representations.
-
EXTERNAL GENERIC-FUNCTION PROCESS-COMPILE
- THING
- &REST
Processes THING to transform all deferred symbols within into their proper compile-able representations.
-
EXTERNAL MACRO WHEN-PACKAGES
- PACKAGES
- &BODY
- BODY
- &REST
Similar to WITH-DEFERRED-LIBRARY, except to be used to compile optional code. The macro returns the transformed body if it can find all packages, otherwise NIL.
-
EXTERNAL MACRO WITH-DEFERRED-LIBRARY
- ASDF-SYSTEM
- &KEY
- PACKAGE
- IF-NOT-LOADED
- &REST
- &BODY
- BODY
- &REST
Turns the body into one capable of using deferred symbols. Specifying deferred symbols works just like other symbols, except prefixing them with #^ . If the #^ reader macro has been overwritten in the standard readtable, please use (named-readtables:in-readtable :deferred) ASDF-SYSTEM --- An ASDF system designator. PACKAGE --- A package designator to use as the default package for deferred symbols. IF-NOT-LOADED ::= NIL | :QUICKLOAD | :LOAD | :AUTO | T NIL will simply skip executing the body if the library has not been loaded. :LOAD will try to use ASDF:LOAD-SYSTEM and :QUICKLISP QL:QUICKLOAD. :AUTO or T will try to do the right thing by checking for Quicklisp and ASDF presence first. If neither can be found, an error is signalled. If the loading operation fails, a warning is signalled and the body is NOT executed. The only place I can think of that deferred symbols are currently not supported for is SETF accessors. This is left out since there's no way to defer SETF-expanders to runtime. You can still SETF symbol-values (special variables f.e.), but an error is signalled if a deferred function is used within SETF.