14.15 Deprecation
(require racket/deprecation) | package: base |
A deprecated function, macro, or other API element is one that’s been formally declared obsolete, typically with an intended replacement that users should migrate to. The racket/deprecation library provides a standardized mechanism for declaring deprecations in a machine-processable manner. These declarations can allow tools such as resyntax to automate migrating code away from deprecated APIs. Note that a dependency on the racket/deprecation library does not imply a dependency on any such tools.
14.15.1 Deprecated Aliases
syntax
(define-deprecated-alias alias-id target-id)
Note that although alias-id is an alias of target-id, it is not considered the same binding as target-id and is not free-identifier=?. This is because the alias binding must be inspectable at compile-time with deprecated-alias? and deprecated-alias-target, and it must remain inspectable even if the alias is provided by a module. This requires a module providing the alias and the target to provide them as two distinct bindings: one which is bound to a deprecated alias transformer and one which isn’t.
> (require racket/deprecation) > (define a 42) > (define-deprecated-alias legacy-a a) > legacy-a 42
14.15.2 Deprecated Alias Transformers
(require racket/deprecation/transformer) | package: base |
The racket/deprecation/transformer module provides compile-time supporting code for the racket/deprecation library, primarily for use in tools that wish to reflect on deprecated code.
A deprecated alias transformer is a kind of rename transformer which signals that the transformer binding is a deprecated alias of the target identifier. This signal is intended for consumption in tools such as editors (which may wish to display a warning when deprecated aliases are used) and automated refactoring systems (which may wish to replace deprecated aliases with their target identifiers automatically).
procedure
(deprecated-alias? v) → boolean?
v : any/c
> (require (for-syntax racket/base racket/deprecation/transformer) racket/deprecation syntax/parse/define)
> (define-syntax-parse-rule (is-deprecated? id:id) #:do [(define-values (transformer _) (syntax-local-value/immediate #'id (λ () (values #false #false))))] #:with result (deprecated-alias? transformer) 'result) > (define-deprecated-alias bad-list list) > (is-deprecated? list) #f
> (is-deprecated? bad-list) #t
procedure
(deprecated-alias target) → deprecated-alias?
target : identifier?
This constructor is not intended for direct use by users who just want to declare a deprecated alias. Such users should prefer the define-deprecated-alias form instead.
procedure
(deprecated-alias-target alias) → identifier?
alias : deprecated-alias?