11module TermInterface
22
33"""
4- istree(x)
4+ istree(x)
55
66Returns `true` if `x` is a term. If true, `operation`, `arguments`
77must also be defined for `x` appropriately.
@@ -11,20 +11,20 @@ istree(x::Type{T}) where {T} = false
1111export istree
1212
1313"""
14- symtype(x)
14+ symtype(x)
1515
1616Returns the symbolic type of `x`. By default this is just `typeof(x)`.
1717Define this for your symbolic types if you want `SymbolicUtils.simplify` to apply rules
1818specific to numbers (such as commutativity of multiplication). Or such
1919rules that may be implemented in the future.
2020"""
2121function symtype (x)
22- typeof (x)
22+ typeof (x)
2323end
2424export symtype
2525
2626"""
27- issym(x)
27+ issym(x)
2828
2929Returns `true` if `x` is a symbol. If true, `nameof` must be defined
3030on `x` and must return a Symbol.
@@ -34,7 +34,7 @@ issym(x::Type{T}) where {T} = false
3434export issym
3535
3636"""
37- exprhead(x)
37+ exprhead(x)
3838
3939If `x` is a term as defined by `istree(x)`, `exprhead(x)` must return a symbol,
4040corresponding to the head of the `Expr` most similar to the term `x`.
@@ -49,7 +49,7 @@ export exprhead
4949
5050
5151"""
52- operation(x)
52+ operation(x)
5353
5454If `x` is a term as defined by `istree(x)`, `operation(x)` returns the
5555head of the term if `x` represents a function call, for example, the head
@@ -59,7 +59,7 @@ function operation end
5959export operation
6060
6161"""
62- arguments(x)
62+ arguments(x)
6363
6464Get the arguments of `x`, must be defined if `istree(x)` is `true`.
6565"""
@@ -68,7 +68,7 @@ export arguments
6868
6969
7070"""
71- unsorted_arguments(x::T)
71+ unsorted_arguments(x::T)
7272
7373If x is a term satisfying `istree(x)` and your term type `T` orovides
7474and optimized implementation for storing the arguments, this function can
@@ -80,7 +80,7 @@ export unsorted_arguments
8080
8181
8282"""
83- arity(x)
83+ arity(x)
8484
8585Returns the number of arguments of `x`. Implicitly defined
8686if `arguments(x)` is defined.
@@ -90,7 +90,7 @@ export arity
9090
9191
9292"""
93- metadata(x)
93+ metadata(x)
9494
9595Return the metadata attached to `x`.
9696"""
@@ -99,36 +99,36 @@ export metadata
9999
100100
101101"""
102- metadata(x, md)
102+ metadata(x, md)
103103
104104Returns a new term which has the structure of `x` but also has
105105the metadata `md` attached to it.
106106"""
107107function metadata (x, data)
108- error (" Setting metadata on $x is not possible" )
108+ error (" Setting metadata on $x is not possible" )
109109end
110110
111111
112112"""
113- similarterm(x, head, args, symtype=nothing; metadata=nothing, exprhead=:call)
113+ similarterm(x, head, args, symtype=nothing; metadata=nothing, exprhead=:call)
114114
115115Returns a term that is in the same closure of types as `typeof(x)`,
116116with `head` as the head and `args` as the arguments, `type` as the symtype
117117and `metadata` as the metadata. By default this will execute `head(args...)`.
118118`x` parameter can also be a `Type`. The `exprhead` keyword argument is useful
119119when manipulating `Expr`s.
120120"""
121- 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
121+ 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
127127end
128128
129- function similarterm (x:: Type{T} , head, args, symtype= nothing ; metadata= nothing , exprhead= :call ) where T
130- ! istree (T) ? head : head (args... )
131- end
129+ function similarterm (x:: Type{T} , head, args, symtype = nothing ; metadata = nothing , exprhead = :call ) where {T}
130+ ! istree (T) ? head : head (args... )
131+ end
132132export similarterm
133133
134134include (" utils.jl" )
0 commit comments