Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the transparent-wrap Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 06:02:06 2022 GMT+0.
Next: Systems, Previous: The transparent-wrap Reference Manual, Up: The transparent-wrap Reference Manual [Contents][Index]
This is a small utility for generating wrapper functions that have the same signature as the functions they wrap so that you can still interactively see the same function signature in the SLIME minibuffer. (It also offers the same feature for macros, which is not quite as difficult but is included for completeness' sake.)
When using lispbuilder-sdl
on SBCL, you may encounter all kinds of floating point errors, but you don't want to disable those errors globally - you want to do your own math before calling out to foreign functions. In that case you can do something like this:
(defpackage :sdl-wrap
(:use :cl)
#.`(:export
,@(loop for symbol being the external-symbols of :sdl
when (and (fboundp symbol)
(eql (symbol-package symbol) (find-package :sdl)))
collect symbol)))
#.`(progn
,@(loop for symbol being the external-symbols of :sdl
when (and (fboundp symbol)
(eql (symbol-package symbol) (find-package :sdl)))
collect
(transparent-wrap:create-transparent-defun
symbol
(lambda (real-function-call)
`(sb-int:with-float-traps-masked (:invalid :overflow :divide-by-zero)
,real-function-call))
:sdl-wrap)))
and fix it without having to massively edit the package's source code or your client code. Just import the wrapper package instead. Now you can get the functionality you need and see that sdl-wrap:draw-string-solid-*
has the signature (string x y &key (justify :left) (surface lispbuilder-sdl:*default-surface*) (font lispbuilder-sdl:*default-font*) (color lispbuilder-sdl:*default-color*))
without manually searching for it!
;; function
(create-transparent-defun 'package:function
(lambda (code)
`(wrap ,code))
:wrapping-package)
(defmacro wrapper (code)
`(wrap ,code))
;; macro
(transparent-defun package:function wrapper :wrapping-package)
;; function
(create-transparent-defmacro package:macro
(lambda (code)
``(wrap ,,code))
:wrapping-package)
(defmacro wrapper (code)
`(wrap ,code))
;; macro
(transparent-defmacro package:macro wrapper :wrapping-package)
For some argument lists, the wrapping layer imposes a considerable overhead, since we have to manually ensure that we only pass exactly the same optional and keyword arguments that appeared in the outer call in case the wrapped function explicitly checks whether any of those arguments were supplied. There are two ways to mitigate this overhead:
Set the keyword argument :force-rest
to t
in create-transparent-defun
. This adds a &rest
parameter when wrapping a function that has &key
arguments but no &rest
argument. This way, the keyword arguments can be passed through with apply
without checking which ones are present, with minimal clutter added to the function signature.
When turning a development build into a production build, you can swap out create-transparent-defun
for create-opaque-defun
to include the same wrapping logic but strip out all the infrastructure for imitating the function signature.
This library uses trivial-arguments
to retrieve function and macro signatures. On some implementations, this will not retrieve default arguments for some parameters. When no signature can be found, transparent-defun
falls back to basic opaque-defun
functionality and creates a wrapper with a &rest
parameter only.
Init-forms can have side effects, and they are normally evaluated in left-to-right order. This library will only hoist init-forms into wrappers until it reaches the first parameter, either optional or keyword, that has a supplied-p check. If you're confident that the ordering of your init-forms won't matter, you can set the keyword argument :allow-reordered-init-forms
to t
and see later parameters' init-forms in the wrapper function signature. You will still not see init-forms for any parameters that have supplied-p checks, since this can still affect the behavior of the wrapped function.
Wrappers for generic functions with &rest
and/or &key
parameters will have those parameters subsumed by a single &rest
parameter to allow for variations in congruent method lambda lists.
Next: Modules, Previous: Introduction, Up: The transparent-wrap Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
A signature-preserving wrapper generator for functions and macros.
Kyle Littler
LLGPL
transparent-wrap
================
[](https://travis-ci.org/DalekBaldwin/transparent-wrap)
This is a small utility for generating wrapper functions that have the same signature as the functions they wrap so that you can still interactively see the same function signature in the SLIME minibuffer. (It also offers the same feature for macros, which is not quite as difficult but is included for completeness’ sake.)
## Table of Contents
* [Example](#example)
* [Basic Usage](#basic-usage)
* [Performance](#performance)
* [Limitations](#limitations)
Example
——-
When using ‘lispbuilder-sdl‘ on SBCL, you may encounter all kinds of floating point errors, but you don’t want to disable those errors globally - you want to do your own math before calling out to foreign functions. In that case you can do something like this:
“‘lisp
(defpackage :sdl-wrap
(:use :cl)
#.‘(:export
,@(loop for symbol being the external-symbols of :sdl
when (and (fboundp symbol)
(eql (symbol-package symbol) (find-package :sdl)))
collect symbol)))
#.‘(progn
,@(loop for symbol being the external-symbols of :sdl
when (and (fboundp symbol)
(eql (symbol-package symbol) (find-package :sdl)))
collect
(transparent-wrap:create-transparent-defun
symbol
(lambda (real-function-call)
‘(sb-int:with-float-traps-masked (:invalid :overflow :divide-by-zero)
,real-function-call))
:sdl-wrap)))
“‘
and fix it without having to massively edit the package’s source code or your client code. Just import the wrapper package instead. Now you can get the functionality you need and see that ‘sdl-wrap:draw-string-solid-*‘ has the signature ‘(string x y &key (justify :left) (surface lispbuilder-sdl:*default-surface*) (font lispbuilder-sdl:*default-font*) (color lispbuilder-sdl:*default-color*))‘ without manually searching for it!
Basic Usage
———–
“‘lisp
;; function
(create-transparent-defun ’package:function
(lambda (code)
‘(wrap ,code))
:wrapping-package)
“‘
“‘lisp
(defmacro wrapper (code)
‘(wrap ,code))
;; macro
(transparent-defun package:function wrapper :wrapping-package)
“‘
“‘lisp
;; function
(create-transparent-defmacro package:macro
(lambda (code)
“(wrap ,,code))
:wrapping-package)
“‘
“‘lisp
(defmacro wrapper (code)
‘(wrap ,code))
;; macro
(transparent-defmacro package:macro wrapper :wrapping-package)
“‘
Performance
———–
For some argument lists, the wrapping layer imposes a considerable overhead, since we have to manually ensure that we only pass exactly the same optional and keyword arguments that appeared in the outer call in case the wrapped function explicitly checks whether any of those arguments were supplied. There are two ways to mitigate this overhead:
1. Set the keyword argument ‘:force-rest‘ to ‘t‘ in ‘create-transparent-defun‘. This adds a ‘&rest‘ parameter when wrapping a function that has ‘&key‘ arguments but no ‘&rest‘ argument. This way, the keyword arguments can be passed through with ‘apply‘ without checking which ones are present, with minimal clutter added to the function signature.
2. When turning a development build into a production build, you can swap out ‘create-transparent-defun‘ for ‘create-opaque-defun‘ to include the same wrapping logic but strip out all the infrastructure for imitating the function signature.
Limitations
———–
This library uses ‘trivial-arguments‘ to retrieve function and macro signatures. On some implementations, this will not retrieve default arguments for some parameters. When no signature can be found, ‘transparent-defun‘ falls back to basic ‘opaque-defun‘ functionality and creates a wrapper with a ‘&rest‘ parameter only.
Init-forms can have side effects, and they are normally evaluated in left-to-right order. This library will only hoist init-forms into wrappers until it reaches the first parameter, either optional or keyword, that has a supplied-p check. If you’re confident that the ordering of your init-forms won’t matter, you can set the keyword argument ‘:allow-reordered-init-forms‘ to ‘t‘ and see later parameters’ init-forms in the wrapper function signature. You will still not see init-forms for any parameters that have supplied-p checks, since this can still affect the behavior of the wrapped function.
Wrappers for generic functions with ‘&rest‘ and/or ‘&key‘ parameters will have those parameters subsumed by a single ‘&rest‘ parameter to allow for variations in congruent method lambda lists.
src (module).
Next: Files, Previous: Systems, Up: The transparent-wrap Reference Manual [Contents][Index]
Modules are listed depth-first from the system components tree.
transparent-wrap (system).
Next: Packages, Previous: Modules, Up: The transparent-wrap Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: transparent-wrap/src/package.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
transparent-wrap (system).
Next: transparent-wrap/src/match.lisp, Previous: transparent-wrap/transparent-wrap.asd, Up: Lisp [Contents][Index]
src (module).
Next: transparent-wrap/src/transparent-wrap.lisp, Previous: transparent-wrap/src/package.lisp, Up: Lisp [Contents][Index]
package.lisp (file).
src (module).
Previous: transparent-wrap/src/match.lisp, Up: Lisp [Contents][Index]
match.lisp (file).
src (module).
Next: Definitions, Previous: Files, Up: The transparent-wrap Reference Manual [Contents][Index]
Packages are listed by definition order.
Next: transparent-wrap-system, Previous: Packages, Up: Packages [Contents][Index]
Previous: transparent-wrap, Up: Packages [Contents][Index]
Next: Indexes, Previous: Packages, Up: The transparent-wrap Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Public Interface, Up: Public Interface [Contents][Index]
Previous: Macros, Up: Public Interface [Contents][Index]
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Internals, Up: Internals [Contents][Index]
Next: Structures, Previous: Special variables, Up: Internals [Contents][Index]
name.
name.
name.
name.
name.
Previous: Ordinary functions, Up: Internals [Contents][Index]
structure-object.
structure-object.
Previous: Definitions, Up: The transparent-wrap Reference Manual [Contents][Index]
Jump to: | (
A C F K M O R S T |
---|
Jump to: | (
A C F K M O R S T |
---|
Next: Data types, Previous: Functions, Up: Indexes [Contents][Index]
Jump to: | *
I K N S W |
---|
Jump to: | *
I K N S W |
---|
Jump to: | A F K M O P R S T |
---|
Jump to: | A F K M O P R S T |
---|