916
916
917
917
918
918
"""
919
- An abstract type representing Unknowns that use the Reactive .jl
919
+ An abstract type representing Unknowns that use the ReactiveBasics .jl
920
920
package. The main types included are `Discrete` and
921
921
`Parameter`. `Discrete` is normally used as inputs inside of models
922
922
and includes an initial value that is reset at every simulation
@@ -927,10 +927,9 @@ variations.
927
927
Because they are Unknowns, UnknownReactive types form MExpr's when
928
928
used in expressions just like Unknowns.
929
929
930
- Many of the methods from Reactive.jl are supported, including `lift`,
931
- `foldl`, `filter`, `dropif`, `droprepeats`, `keepwhen`, `dropwhen`,
932
- `sampleon`, and `merge`. Use `reinit` to reinitialize a Discrete or a
933
- Parameter (equivalent to `Reactive.push!`).
930
+ Many of the methods from ReactiveBasics.jl are supported, including `map`,
931
+ `foldp`, `filter`, and `merge`. Use `reinit` to reinitialize a Discrete or a
932
+ Parameter (equivalent to `push!`).
934
933
935
934
"""
936
935
abstract UnknownReactive{T} <: UnknownVariable
@@ -940,40 +939,40 @@ Discrete is a type for discrete variables. These are only changed
940
939
during events. They are not used by the integrator. Because they are
941
940
not used by the integrator, almost any type can be used as a discrete
942
941
variable. Discrete variables wrap a Signal from the
943
- [Reactive .jl](http://julialang .org/Reactive .jl/ ) package.
942
+ [ReactiveBasics .jl](http://github .org/tshort/ReactiveBasics .jl) package.
944
943
945
944
### Constructors
946
945
947
946
```julia
948
947
Discrete(initialvalue = 0.0)
949
- Discrete(x::Reactive .Signal, initialvalue)
948
+ Discrete(x::ReactiveBasics .Signal, initialvalue)
950
949
```
951
950
952
951
Without arguments, `Discrete()` uses an initial value of 0.0.
953
952
954
953
### Arguments
955
954
956
955
* `initialvalue` : initial value and type information, defaults to 0.0
957
- * `x::Reactive .Signal` : a `Signal` from the Reactive .jl package.
956
+ * `x::ReactiveBasics .Signal` : a `Signal` from the ReactiveBasics .jl package.
958
957
959
958
### Details
960
959
961
960
`Discrete` is the main input type for discrete variables. By default,
962
- it wraps a `Reactive .Signal` type. `Discrete` variables support data
963
- flow using Reactive .jl. Use `reinit` to update Discrete variables. Use
964
- `lift ` to create additional `UnknownReactive` types that depend on the
965
- `Discrete` input. Use `foldl ` for actions that remember state. For
961
+ it wraps a `ReactiveBasics .Signal` type. `Discrete` variables support data
962
+ flow using ReactiveBasics .jl. Use `reinit` to update Discrete variables. Use
963
+ `map ` to create additional `UnknownReactive` types that depend on the
964
+ `Discrete` input. Use `foldp ` for actions that remember state. For
966
965
more information on *Reactive Programming*, see the
967
- [Reactive .jl](http://julialang .org/Reactive .jl/ ) package.
966
+ [ReactiveBasics .jl](http://github .org/tshort/ReactiveBasics .jl) package.
968
967
969
968
"""
970
- type Discrete{T <: Reactive .Signal } <: UnknownReactive{T}
969
+ type Discrete{T <: ReactiveBasics .Signal } <: UnknownReactive{T}
971
970
signal:: T
972
971
initialvalue
973
972
end
974
- # Discrete(x::Reactive .SignalSource) = Discrete(x, zero(x))
975
- Discrete (initialval) = Discrete (Reactive . Signal (initialval), initialval)
976
- Discrete () = Discrete (Reactive . Signal (0.0 ), 0.0 )
973
+ # Discrete(x::ReactiveBasics .SignalSource) = Discrete(x, zero(x))
974
+ Discrete (initialval) = Discrete (ReactiveBasics . Signal (initialval), initialval)
975
+ Discrete () = Discrete (ReactiveBasics . Signal (0.0 ), 0.0 )
977
976
978
977
"""
979
978
An `UnknownReactive` type that is useful for passing parameters at the
@@ -983,20 +982,20 @@ top level.
983
982
984
983
```julia
985
984
Parameter(x = 0.0)
986
- Parameter(sig::Reactive .Signal}
985
+ Parameter(sig::ReactiveBasics .Signal}
987
986
```
988
987
989
988
### Arguments
990
989
991
990
* `x` : initial value and type information, defaults to 0.0
992
- * `sig` : A `Reactive .Signal
991
+ * `sig` : A `ReactiveBasics .Signal`
993
992
994
993
### Details
995
994
996
995
Parameters can be reinitialized with `reinit`, either externally or
997
996
inside models. If you want Parameters to be read-only, wrap them in
998
997
another UnknownReactive before passing to models. For example, use
999
- `param_read_only = lift (x -> x, param)`.
998
+ `param_read_only = map (x -> x, param)`.
1000
999
1001
1000
### Examples
1002
1001
@@ -1014,17 +1013,18 @@ vwp3 = sim(ss, 10.0) # should be the same as vwp1
1014
1013
```
1015
1014
1016
1015
"""
1017
- type Parameter{T <: Reactive .Signal } <: UnknownReactive{T}
1016
+ type Parameter{T <: ReactiveBasics .Signal } <: UnknownReactive{T}
1018
1017
signal:: T
1019
1018
end
1020
- Parameter (x = 0.0 ) = Parameter (Reactive. Signal (x))
1019
+ Parameter (x = 0.0 ) = Parameter (ReactiveBasics. Signal (x))
1020
+ Parameter (x:: UnknownReactive ) = x
1021
1021
1022
1022
name (a:: UnknownReactive ) = " discrete"
1023
- value {T} (x:: UnknownReactive{T} ) = Reactive . value (x. signal)
1023
+ value {T} (x:: UnknownReactive{T} ) = ReactiveBasics . value (x. signal)
1024
1024
signal (x:: UnknownReactive ) = x. signal
1025
1025
1026
- Reactive . push! {T} (x:: Discrete{Reactive .Signal{T}} , y) = mexpr (:call , :(Reactive . push!), x. signal, y)
1027
- Reactive . push! {T} (x:: Parameter{Reactive .Signal{T}} , y) = Reactive . push! (x. signal, y)
1026
+ ReactiveBasics . push! {T} (x:: Discrete{ReactiveBasics .Signal{T}} , y) = mexpr (:call , :(ReactiveBasics . push!), x. signal, y)
1027
+ ReactiveBasics . push! {T} (x:: Parameter{ReactiveBasics .Signal{T}} , y) = ReactiveBasics . push! (x. signal, y)
1028
1028
1029
1029
1030
1030
"""
@@ -1065,8 +1065,8 @@ end
1065
1065
See also [IdealThyristor](../../lib/electrical/#idealthyristor) in the standard library.
1066
1066
1067
1067
"""
1068
- reinit {T} (x:: Discrete{Reactive .Signal{T}} , y) = MExpr (:( Reactive . push! ($ (x. signal), $ y); Reactive . run_till_now ( ) ))
1069
- reinit {T} (x:: Parameter{Reactive .Signal{T}} , y) = Reactive . push! (x. signal, y)
1068
+ reinit {T} (x:: Discrete{ReactiveBasics .Signal{T}} , y) = MExpr (:( ReactiveBasics . push! ($ (x. signal), $ y) ))
1069
+ reinit {T} (x:: Parameter{ReactiveBasics .Signal{T}} , y) = ReactiveBasics . push! (x. signal, y)
1070
1070
1071
1071
function reinit (x, y)
1072
1072
sim_info (" reinit: $(x[]) to $y " , 2 )
@@ -1093,18 +1093,10 @@ Create a new UnknownReactive type that links to existing
1093
1093
UnknownReactive types (like Discrete and Parameter).
1094
1094
1095
1095
```julia
1096
- lift{T}(f::Function, inputs::UnknownReactive{T}...)
1097
- lift{T}(f::Function, t::Type, inputs::UnknownReactive{T}...)
1098
1096
map{T}(f::Function, inputs::UnknownReactive{T}...)
1099
1097
map{T}(f::Function, t::Type, inputs::UnknownReactive{T}...)
1100
1098
```
1101
1099
1102
- See also
1103
- [Reactive.lift](http://julialang.org/Reactive.jl/api.html#lift)] and
1104
- the [@liftd](#liftd) helper macro to ease writing expressions.
1105
-
1106
- Note that `lift` is being transitioned to `Base.map`.
1107
-
1108
1100
### Arguments
1109
1101
1110
1102
* `f::Function` : the transformation function; takes one argument for
@@ -1119,8 +1111,8 @@ function.
1119
1111
1120
1112
```julia
1121
1113
a = Discrete(1)
1122
- b = lift (x -> x + 1, a)
1123
- c = lift ((x,y) -> x * y, a, b)
1114
+ b = map (x -> x + 1, a)
1115
+ c = map ((x,y) -> x * y, a, b)
1124
1116
reinit(a, 3)
1125
1117
b # now 4
1126
1118
c # now 12
@@ -1131,11 +1123,11 @@ Note that you can use Discretes and Parameters in expressions that
1131
1123
create MExprs. Compare the following:
1132
1124
1133
1125
```julia
1134
- j = lift ((x,y) = x * y, a, b)
1126
+ j = map ((x,y) = x * y, a, b)
1135
1127
k = a * b
1136
1128
```
1137
1129
1138
- In this example, `j` uses `lift ` to immediately connect to `a` and
1130
+ In this example, `j` uses `map ` to immediately connect to `a` and
1139
1131
`b`. `k` is an MExpr with `a * b` embedded inside. When `j` is used in
1140
1132
a model, the `j` UnknownReactive object is embedded in the model, and it
1141
1133
is updated automatically. With `k`, `a * b` is inserted into the
@@ -1144,34 +1136,22 @@ in the residual calculation. The advantage of the `a * b` approach is
1144
1136
that the expression can include Unknowns.
1145
1137
1146
1138
"""
1147
- Reactive. lift {T} (f:: Function , input:: UnknownReactive{T} , inputs:: UnknownReactive{T} ...) = Parameter (map (f, input. signal, [input. signal for input in inputs]. .. ))
1148
-
1149
- Reactive. lift {T} (f:: Function , t:: Type , input:: UnknownReactive{T} , inputs:: UnknownReactive{T} ...) = Parameter (map (f, t, input. signal, [input. signal for input in inputs]. .. ))
1150
-
1151
1139
Base. map {T} (f:: Function , input:: UnknownReactive{T} , inputs:: UnknownReactive{T} ...) = Parameter (map (f, input. signal, [input. signal for input in inputs]. .. ))
1152
1140
1153
1141
Base. map {T} (f:: Function , t:: Type , input:: UnknownReactive{T} , inputs:: UnknownReactive{T} ...) = Parameter (map (f, t, input. signal, [input. signal for input in inputs]. .. ))
1154
1142
1155
- Reactive. filter {T} (pred:: Function , v0, s:: UnknownReactive{T} ) = Parameter (filter (pred, v0, s. signal))
1156
- Reactive. dropwhen {T} (test:: Signal{Bool} , v0, s:: UnknownReactive{T} ) = Parameter (dropwhen (pred, v0, s. signal))
1157
- Reactive. sampleon (s1:: UnknownReactive , s2:: UnknownReactive ) = Parameter (sampleon (s1. signal, s2. signal))
1158
- # Reactive.merge() = nothing
1159
- Reactive. merge (signals:: UnknownReactive... ) = Parameter (merge (map (signal, signals)))
1160
- Reactive. droprepeats (s:: UnknownReactive ) = Parameter (droprepeats (signal (s)))
1161
- Reactive. dropif (pred:: Function , v0, s:: UnknownReactive ) = Parameter (dropif (pred, v0, s. signal))
1162
- Reactive. keepwhen (test:: UnknownReactive{Signal{Bool}} , v0, s:: UnknownReactive ) = Parameter (keepwhen (test. signal, v0, s. signal))
1143
+ Base. filter {T} (pred:: Function , v0, s:: UnknownReactive{T} ) = Parameter (filter (pred, v0, s. signal))
1144
+ Base. merge (signals:: UnknownReactive... ) = Parameter (merge (map (signal, signals)))
1145
+ ReactiveBasics. flatmap (f, inputs:: UnknownReactive... ) = Parameter (flatmap (f, [x. signal for x in inputs]. .. ))
1163
1146
1164
1147
1165
1148
1166
1149
"""
1167
- "Fold over time " -- an UnknownReactive updated based on stored state
1150
+ "Fold over past values " -- an UnknownReactive updated based on stored state
1168
1151
and additional inputs.
1169
1152
1170
- See also
1171
- [Reactive.foldl](http://julialang.org/Reactive.jl/api.html#foldl)].
1172
-
1173
1153
```julia
1174
- foldl (f::Function, v0, inputs::UnknownReactive{T}...)
1154
+ foldp (f::Function, v0, inputs::UnknownReactive{T}...)
1175
1155
```
1176
1156
1177
1157
### Arguments
@@ -1191,8 +1171,8 @@ foldl(f::Function, v0, inputs::UnknownReactive{T}...)
1191
1171
See the definition of [pre](#pre) for an example.
1192
1172
1193
1173
"""
1194
- Reactive . foldl {T,S} (f,v0:: T , signal:: UnknownReactive{S} , signals:: UnknownReactive{S} ...) =
1195
- Parameter (Reactive . foldl (f, v0, signal. signal, [s. signal for s in signals]. .. ))
1174
+ ReactiveBasics . foldp {T,S} (f,v0:: T , signal:: UnknownReactive{S} , signals:: UnknownReactive{S} ...) =
1175
+ Parameter (ReactiveBasics . foldp (f, v0, signal. signal, [s. signal for s in signals]. .. ))
1196
1176
1197
1177
1198
1178
@@ -1204,7 +1184,7 @@ A helper for an expression of UnknownReactive variables
1204
1184
```
1205
1185
1206
1186
Note that the expression should not contain Unknowns. To mark the
1207
- Discrete variables, enter them as Symbols. This uses `lift ()`.
1187
+ Discrete variables, enter them as Symbols. This uses `map ()`.
1208
1188
1209
1189
### Arguments
1210
1190
@@ -1221,15 +1201,15 @@ x = Discrete(true)
1221
1201
y = Discrete(false)
1222
1202
z = @liftd :x & !:y
1223
1203
## equivalent to:
1224
- z2 = lift ((x, y) -> x & !y, x, y)
1204
+ z2 = map ((x, y) -> x & !y, x, y)
1225
1205
```
1226
1206
1227
1207
"""
1228
1208
macro liftd (ex)
1229
1209
varnames = Any[]
1230
1210
body = replace_syms (ex, varnames)
1231
1211
front = Expr (:tuple , varnames... )
1232
- esc (:( Reactive . lift ($ front -> $ body, $ (varnames... )) ))
1212
+ esc (:( map ($ front -> $ body, $ (varnames... )) ))
1233
1213
end
1234
1214
replace_syms (x, varnames) = x
1235
1215
function replace_syms (e:: Expr , varnames)
@@ -1265,8 +1245,8 @@ pre(x::UnknownReactive)
1265
1245
1266
1246
"""
1267
1247
function pre {T} (x:: UnknownReactive{T} )
1268
- Reactive . lift (x -> x[1 ],
1269
- Reactive . foldl ((a,b) -> (a[2 ], b), (zero (Sims. value (x)), Sims. value (x)), x))
1248
+ map (x -> x[1 ],
1249
+ ReactiveBasics . foldp ((a,b) -> (a[2 ], b), (zero (Sims. value (x)), Sims. value (x)), x))
1270
1250
end
1271
1251
1272
1252
0 commit comments