You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -26,7 +16,7 @@ but suppose you want to provide additional functionality if the `Gadfly` package
26
16
Requires.jl exports a macro, `@require`, that allows you to specify that some code is conditional on having both packages available.
27
17
28
18
`@require` must be within the [`__init__`](https://docs.julialang.org/en/v1/manual/modules/#Module-initialization-and-precompilation-1) method for your module.
29
-
Here's an example that will create a new method of a function called `media` only when both packages are present:
19
+
Here's an example that will create a new method of a function called `myfunction` only when both packages are present:
30
20
31
21
```julia
32
22
module MyPkg
@@ -42,12 +32,12 @@ end
42
32
end# module
43
33
```
44
34
45
-
`Gadfly` is the name of the package, and the value in the string is the UUID which may be obtained
35
+
The value in the string is Gadfly's UUID; this information may be obtained
46
36
by finding the package in the registry ([JuliaRegistries](https://github.com/JuliaRegistries/General) for public packages).
47
37
Note that the `Gadfly.Plot` type may not be available when you load `MyPkg`, but `@require`
48
38
handles this situation without trouble.
49
39
50
-
For larger amounts of code you can use `include`inside the `@require` statement:
40
+
For larger amounts of code you can use `include`as the argument to the `@require` statement:
51
41
52
42
```julia
53
43
function__init__()
@@ -66,6 +56,8 @@ end
66
56
67
57
if you wish to exploit precompilation for the new code.
68
58
59
+
## Demo
60
+
69
61
For a complete demo, consider the following file named `"Reqs.jl"`:
70
62
71
63
```julia
@@ -80,8 +72,7 @@ end
80
72
end
81
73
```
82
74
83
-
Here's a complete demo using this file (note that if this were a registered package you could
84
-
replace the first two commands with `using Reqs`):
75
+
Here's a session that shows how `Colors` is only loaded after you've imported `JSON`:
85
76
86
77
```julia
87
78
julia>include("Reqs.jl")
@@ -100,3 +91,5 @@ Colors
100
91
julia> Reqs.Colors.RGB(1,0,0)
101
92
RGB{N0f8}(1.0,0.0,0.0)
102
93
```
94
+
95
+
Note that if `Reqs` were a registered package you could replace the first two commands with `using Reqs`.
0 commit comments