You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-119Lines changed: 1 addition & 119 deletions
Original file line number
Diff line number
Diff line change
@@ -5,123 +5,5 @@ Its purpose is to provide a shared interface between various symbolic programmin
5
5
[SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl), [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl) and [Metatheory.jl](https://github.com/0x0f0f0f/Metatheory.jl).
6
6
7
7
## Docs
8
-
You should define the following methods for an expression tree type `T` with symbol types `S` to work
9
-
with TermInterface.jl, and therefore with [SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl)
10
-
and [Metatheory.jl](https://github.com/0x0f0f0f/Metatheory.jl).
11
8
12
-
#### `isexpr(x::T)`
13
-
14
-
Returns `true` if `x` is an expression tree. If true, `head(x)` and `children(x)` methods must be defined for `x`.
15
-
Optionally, if `x` represents a function call, `iscall(x)` should be true, and `operation(x)` and `arguments(x)` should also be defined.
16
-
17
-
#### `iscall(x::T)`
18
-
19
-
Returns `true` if `x` is a function call expression. If true, `operation(x)`, `arguments(x)`
20
-
must also be defined for `x`.
21
-
22
-
If `iscall(x)` is true, then also `isexpr(x)`*must* be true. The other way around is not true.
23
-
(A function call is always an expression node, but not every expression tree represents a function call).
24
-
25
-
This means that, `head(x)` and `children(x)` must be defined. Together
26
-
with `operation(x)` and `arguments(x)`.
27
-
28
-
**Examples:**
29
-
30
-
In a functional language, all expression trees are function calls (e.g. SymbolicUtils.jl).
31
-
Let's say that you have an hybrid array and functional language. `iscall` on the expression `v[i]`
32
-
is `false`, and `iscall` on expression `f(x)` is `true`, but both of them are nested
33
-
expressions, and `isexpr` is `true` on both.
34
-
35
-
The same goes for Julia `Expr`. An `Expr(:block, ...)` is *not a function call*
36
-
and has no `operation` and `arguments`, but has a `head` and `children`.
37
-
38
-
39
-
The distinction between `head`/`children` and `operation`/`arguments` is needed
40
-
when dealing with languages that are *not representing function call operations as their head*.
41
-
The main example is `Expr(:call, :f, :x)`: it has both a `head` and an `operation`, which are
42
-
respectively `:call` and `:f`.
43
-
44
-
In other symbolic expression languages, such as SymbolicUtils.jl, the `head` of a node
45
-
can correspond to `operation` and `children` can correspond to `arguments`.
46
-
47
-
#### `head(x)`
48
-
49
-
Returns the head of the S-expression.
50
-
51
-
#### `children(x)`
52
-
53
-
Returns the children (aka tail) of the S-expression.
54
-
55
-
#### `operation(x)`
56
-
57
-
Returns the function a function call expression is calling. `iscall(x)` must be
58
-
true as a precondition.
59
-
60
-
#### `arguments(x)`
61
-
62
-
Returns the arguments to the function call in a function call expression.
This package contains definitions for common functions that are useful for symbolic expression manipulation.
4
+
Its purpose is to provide a shared interface between various symbolic programming Julia packages, for example
5
+
[SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl), [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl) and [Metatheory.jl](https://github.com/0x0f0f0f/Metatheory.jl).
6
+
7
+
You should define the following methods for your expression tree type to work
8
+
with TermInterface.jl, and therefore with [SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl)
9
+
and [Metatheory.jl](https://github.com/0x0f0f0f/Metatheory.jl).
10
+
11
+
## Examples
12
+
13
+
### Function call Julia Expressions
14
+
15
+
```julia
16
+
ex = :(f(a, b))
17
+
@testhead(ex) ==:call
18
+
@testchildren(ex) == [:f, :a, :b]
19
+
@testoperation(ex) ==:f
20
+
@testarguments(ex) == [:a, :b]
21
+
@testisexpr(ex)
22
+
@testiscall(ex)
23
+
@test ex ==maketerm(Expr, :call, [:f, :a, :b], nothing)
24
+
```
25
+
26
+
27
+
### Non-function call Julia Expressions
28
+
29
+
```julia
30
+
ex = :(arr[i, j])
31
+
@testhead(ex) ==:ref
32
+
@test_throws ErrorException operation(ex)
33
+
@test_throws ErrorException arguments(ex)
34
+
@testisexpr(ex)
35
+
@test!iscall(ex)
36
+
@test ex ==maketerm(Expr, :ref, [:arr, :i, :j], nothing)
0 commit comments