Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,15 @@ function Base.setproperty!(sys::AbstractSystem, prop::Symbol, val)
end
end

function apply_to_variables(f::F, ex) where {F}
ex = value(ex)
apply_to_variables(f::F, ex) where {F} = _apply_to_variables(f, ex)
apply_to_variables(f::F, ex::Num) where {F} = wrap(_apply_to_variables(f, unwrap(ex)))
function _apply_to_variables(f::F, ex) where {F}
if isvariable(ex)
return f(ex)
end
istree(ex) || return ex
similarterm(ex, apply_to_variables(f, operation(ex)),
map(Base.Fix1(apply_to_variables, f), arguments(ex)),
similarterm(ex, _apply_to_variables(f, operation(ex)),
map(Base.Fix1(_apply_to_variables, f), arguments(ex)),
metadata = metadata(ex))
end

Expand Down
1 change: 1 addition & 0 deletions test/variable_scope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Test
b = ParentScope(b)
c = ParentScope(ParentScope(c))
d = GlobalScope(d)
@test all(x -> x isa Num, [b, c, d])

# ensure it works on Term too
LocalScope(e.val)
Expand Down