Skip to content

Commit 50c266c

Browse files
committed
check in interface.jl
1 parent e2484ec commit 50c266c

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

src/interface.jl

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""
2+
istree(x)
3+
4+
Returns `true` if `x` is a term. If true, `operation`, `arguments`
5+
must also be defined for `x` appropriately.
6+
"""
7+
istree(x) = false
8+
9+
"""
10+
symtype(x)
11+
12+
Returns the symbolic type of `x`. By default this is just `typeof(x)`.
13+
Define this for your symbolic types if you want `SymbolicUtils.simplify` to apply rules
14+
specific to numbers (such as commutativity of multiplication). Or such
15+
rules that may be implemented in the future.
16+
"""
17+
function symtype(x)
18+
typeof(x)
19+
end
20+
21+
"""
22+
issym(x)
23+
24+
Returns `true` if `x` is a symbol. If true, `nameof` must be defined
25+
on `x` and must return a Symbol.
26+
"""
27+
issym(x) = false
28+
29+
"""
30+
operation(x)
31+
32+
If `x` is a term as defined by `istree(x)`, `operation(x)` returns the
33+
head of the term if `x` represents a function call, for example, the head
34+
is the function being called.
35+
"""
36+
function operation end
37+
38+
"""
39+
arguments(x)
40+
41+
Get the arguments of `x`, must be defined if `istree(x)` is `true`.
42+
"""
43+
function arguments end
44+
45+
"""
46+
unsorted_arguments(x::T)
47+
48+
If x is a term satisfying `istree(x)` and your term type `T` orovides
49+
and optimized implementation for storing the arguments, this function can
50+
be used to retrieve the arguments when the order of arguments does not matter
51+
but the speed of the operation does.
52+
"""
53+
unsorted_arguments(x) = arguments(x)
54+
arity(x) = length(unsorted_arguments(x))
55+
56+
"""
57+
metadata(x)
58+
59+
Return the metadata attached to `x`.
60+
"""
61+
metadata(x) = nothing
62+
63+
"""
64+
metadata(x, md)
65+
66+
Returns a new term which has the structure of `x` but also has
67+
the metadata `md` attached to it.
68+
"""
69+
function metadata(x, data)
70+
error("Setting metadata on $x is not possible")
71+
end
72+
73+
"""
74+
similarterm(x, head, args, symtype=nothing; metadata=nothing, exprhead=:call)
75+
76+
Returns a term that is in the same closure of types as `typeof(x)`,
77+
with `head` as the head and `args` as the arguments, `type` as the symtype
78+
and `metadata` as the metadata. By default this will execute `head(args...)`.
79+
`x` parameter can also be a `Type`. The `exprhead` keyword argument is useful
80+
when manipulating `Expr`s.
81+
"""
82+
function similarterm end

0 commit comments

Comments
 (0)