Skip to content

Commit 57ccf33

Browse files
Clean up variables.jl
1 parent 3926542 commit 57ccf33

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/variables.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,25 @@ struct Variable <: Function
88
end
99
(x::Variable)(args...) = Operation(x, collect(Expression, args))
1010

11+
Base.isequal(x::Variable, y::Variable) = (x.name, x.known) == (y.name, y.known)
12+
Base.show(io::IO, x::Variable) = print(io, x.name)
13+
1114

1215
struct Constant <: Expression
1316
value::Number
1417
end
1518
Base.get(c::Constant) = c.value
1619

17-
1820
Base.iszero(ex::Expression) = isa(ex, Constant) && iszero(ex.value)
1921
Base.isone(ex::Expression) = isa(ex, Constant) && isone(ex.value)
2022

21-
2223
# Variables use isequal for equality since == is an Operation
23-
Base.isequal(x::Variable, y::Variable) = (x.name, x.known) == (y.name, y.known)
24-
Base.isequal(::Variable, ::Number) = false
25-
Base.isequal(::Number, ::Variable) = false
26-
Base.isequal(::Variable, ::Constant) = false
27-
Base.isequal(::Constant, ::Variable) = false
2824
Base.isequal(c::Constant, n::Number) = c.value == n
2925
Base.isequal(n::Number, c::Constant) = c.value == n
3026
Base.isequal(a::Constant, b::Constant) = a.value == b.value
3127

32-
Base.convert(::Type{Expr}, x::Variable) = x
3328
Base.convert(::Type{Expr}, c::Constant) = c.value
3429

35-
Base.show(io::IO, x::Variable) = print(io, x.name)
3630

3731
# Build variables more easily
3832
function _parse_vars(macroname, known, x)

0 commit comments

Comments
 (0)