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
@@ -8,34 +8,119 @@ There are some kinds of changes that Revise (or often, Julia itself) cannot inco
8
8
9
9
These kinds of changes require that you restart your Julia session.
10
10
11
-
During early stages of development, it's quite common to want to change type definitions. You can work around Julia's/Revise's limitations by temporary renaming:
11
+
During early stages of development, it's quite common to want to change type definitions. You can work around Julia's/Revise's limitations by temporary renaming. We'll illustrate this below, using `write` to be explicit about when updates to the file happen. But in ordinary usage, these are changes you'd likely make with your editor.
12
12
13
13
```julia
14
-
# 1st version
15
-
struct FooStruct1
16
-
bar::Int
17
-
end
18
-
FooStruct = FooStruct1
19
-
functionprocessFoo(foo::FooStruct)
20
-
@info foo.bar
21
-
end
22
-
```
23
-
and then the type can be updated like
24
-
```julia
25
-
# 2nd version
26
-
struct FooStruct2 # change version here
27
-
bar::Int
28
-
str::String
29
-
end
30
-
FooStruct = FooStruct2 # change version here
31
-
functionprocessFoo(foo::FooStruct) # no need to change this
struct FooStruct2 <: AbstractFooStruct # change version nuumber
62
+
bar::Float64 # change type of the field
63
+
end
64
+
FooStruct = FooStruct2 # update alias reference
65
+
function processFoo(foo::AbstractFooStruct)
66
+
@info foo.bar
67
+
end
68
+
69
+
end
70
+
""")
71
+
234
72
+
73
+
julia> FooStruct # make sure FooStruct refers to FooStruct2
74
+
MyPkg.FooStruct2
75
+
76
+
julia>processFoo(FooStruct(3.5))
77
+
[ Info:3.5
34
78
```
79
+
80
+
Here, note that we made two changes: we updated the "version number" of FooStruct when we changed something about its fields, and we also re-assigned FooStruct to alias the new version. We did not change the definition of any methods that have been typed AbstractFooStruct.
81
+
35
82
This works as long as the new type name doesn't conflict with an existing name; within a session you need to change the name each time you change the definition.
36
83
37
84
Once your development has converged on a solution, it's best to switch to the "permanent" name: in the example above, `FooStruct` is a non-constant global variable, and if used internally in a function there will be consequent performance penalties. Switching to the permanent name will force you to restart your session.
38
85
86
+
```julia
87
+
julia>isconst(MyPkg, :FooStruct)
88
+
true
89
+
90
+
julia>write("src/MyPkg.jl","""
91
+
module MyPkg
92
+
93
+
export FooStruct, processFoo
94
+
95
+
abstract type AbstractFooStruct end # this could be removed
96
+
struct FooStruct <: AbstractFooStruct # change to just FooStruct
97
+
bar::Float64
98
+
end
99
+
100
+
function processFoo(foo::AbstractFooStruct) # consider changing to FooStruct
101
+
@info foo.bar
102
+
end
103
+
104
+
end
105
+
""")
106
+
107
+
julia>run(Base.julia_cmd()) # start a new Julia session, alternatively exit() and restart julia
108
+
109
+
110
+
julia>using Pkg, Revise # NEW Julia Session
111
+
112
+
julia> Pkg.activate(".")
113
+
Activating project at `~/blah/MyPkg`
114
+
115
+
julia>using MyPkg
116
+
Precompiling MyPkg
117
+
1 dependency successfully precompiled in2 seconds
118
+
119
+
julia>isconst(MyPkg, :FooStruct)
120
+
true
121
+
122
+
```
123
+
39
124
In addition, some situations may require special handling:
0 commit comments