-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
24 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
""" | ||
Tryable <: Function | ||
An *implementation detail* of `Try.@function`. | ||
This is not exposed as an API because: | ||
* It may be required for a callable to be in another type hierarchy. Such callables are | ||
incompatible with the code written with `_ isa Tryable`. | ||
* When a Tryable function is part of stack trace, its printing is not great. It may be | ||
better to just use a plain `function` and define `istryable`. | ||
* The tryability many depend on some run-time properties. | ||
""" | ||
abstract type Tryable <: Function end | ||
|
||
Try.istryable(::Any) = false | ||
Try.istryable(::Tryable) = true | ||
|
||
const var"@define_function" = var"@function" | ||
|
||
macro define_function(name::Symbol) | ||
typename = gensym("typeof_$name") | ||
quote | ||
struct $typename <: $Try.Tryable end | ||
struct $typename <: $Tryable end | ||
const $name = $typename() | ||
$Base.nameof(::$typename) = $(QuoteNode(name)) | ||
end |> esc | ||
end | ||
|
||
(fn::Try.Tryable)(args...; kwargs...) = Causes.notimplemented(fn, args, kwargs) | ||
(fn::Tryable)(args...; kwargs...) = Causes.notimplemented(fn, args, kwargs) | ||
|
||
# TODO: show methods |