Skip to content

Commit 91f77ff

Browse files
authored
Merge pull request #12 from JuliaSymbolics/ale/fixegraphs
`similarterm`, `issym` and `istree` can be called only on objects, not on types
2 parents 9ef4c24 + 94b79e4 commit 91f77ff

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TermInterface"
22
uuid = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
33
authors = ["Shashi Gowda <[email protected]>", "Alessandro Cheli <[email protected]>"]
4-
version = "0.2.3"
4+
version = "0.3.0"
55

66
[compat]
77
julia = "1"

src/TermInterface.jl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ module TermInterface
66
Returns `true` if `x` is a term. If true, `operation`, `arguments`
77
must also be defined for `x` appropriately.
88
"""
9-
istree(x) = istree(typeof(x))
10-
istree(x::Type{T}) where {T} = false
9+
istree(x) = false
1110
export istree
1211

1312
"""
@@ -29,8 +28,7 @@ export symtype
2928
Returns `true` if `x` is a symbol. If true, `nameof` must be defined
3029
on `x` and must return a Symbol.
3130
"""
32-
issym(x) = issym(typeof(x))
33-
issym(x::Type{T}) where {T} = false
31+
issym(x) = false
3432
export issym
3533

3634
"""
@@ -119,16 +117,9 @@ and `metadata` as the metadata. By default this will execute `head(args...)`.
119117
when manipulating `Expr`s.
120118
"""
121119
function similarterm(x, head, args, symtype = nothing; metadata = nothing, exprhead = nothing)
122-
if exprhead === nothing
123-
similarterm(typeof(x), head, args, symtype; metadata = metadata)
124-
else
125-
similarterm(typeof(x), head, args, symtype; metadata = metadata, exprhead = exprhead)
126-
end
120+
!istree(x) ? head : head(args...)
127121
end
128122

129-
function similarterm(x::Type{T}, head, args, symtype = nothing; metadata = nothing, exprhead = :call) where {T}
130-
!istree(T) ? head : head(args...)
131-
end
132123
export similarterm
133124

134125
include("utils.jl")

src/expr.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file contains default definitions for TermInterface methods on Julia
22
# Builtin Expr type.
33

4-
istree(x::Type{Expr}) = true
4+
istree(x::Expr) = true
55
exprhead(e::Expr) = e.head
66

77
operation(e::Expr) = expr_operation(e, Val{exprhead(e)}())
@@ -16,10 +16,6 @@ expr_arguments(e::Expr, ::Union{Val{:call},Val{:macrocall}}) = e.args[2:end]
1616
expr_arguments(e::Expr, _) = e.args
1717

1818

19-
function similarterm(x::Type{Expr}, head, args, symtype = nothing; metadata = nothing, exprhead = :call)
20-
expr_similarterm(head, args, Val{exprhead}())
21-
end
22-
2319
function similarterm(x::Expr, head, args, symtype = nothing; metadata = nothing, exprhead = exprhead(x))
2420
expr_similarterm(head, args, Val{exprhead}())
2521
end

test/runtests.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using TermInterface
22
using Test
33

4-
@testset "Expr" begin
5-
ex = :(f(a,b))
4+
@testset "Expr" begin
5+
ex = :(f(a, b))
66
@test operation(ex) == :f
77
@test arguments(ex) == [:a, :b]
88
@test exprhead(ex) == :call
@@ -12,8 +12,6 @@ using Test
1212
@test operation(ex) == getindex
1313
@test arguments(ex) == [:arr, :i, :j]
1414
@test exprhead(ex) == :ref
15-
@test ex == similarterm(Expr, :ref, [:arr, :i, :j]; exprhead=:ref)
15+
@test ex == similarterm(ex, :ref, [:arr, :i, :j]; exprhead = :ref)
1616
@test ex == similarterm(ex, :ref, [:arr, :i, :j])
1717
end
18-
19-
# TODO add SymbolicUtils tests??

0 commit comments

Comments
 (0)