|
1 | 1 | module TermInterface
|
2 | 2 |
|
3 |
| -function isterm end |
| 3 | +""" |
| 4 | + isterm(x) |
| 5 | +
|
| 6 | +Returns `true` if `x` is a term. If true, `gethead`, `getargs` |
| 7 | +must also be defined for `x` appropriately. |
| 8 | +""" |
| 9 | +isterm(x) = false |
| 10 | + |
| 11 | +""" |
| 12 | + symtype(x) |
| 13 | +
|
| 14 | +Returns the symbolic type of `x`. By default this is just `typeof(x)`. |
| 15 | +""" |
| 16 | +function symtype(x) |
| 17 | + typeof(x) |
| 18 | +end |
| 19 | + |
| 20 | +""" |
| 21 | + issym(x) |
| 22 | +
|
| 23 | +Returns `true` if `x` is a symbol. If true, `nameof` must be defined |
| 24 | +on `x` and must return a Symbol. |
| 25 | +""" |
4 | 26 | function issym end
|
| 27 | + |
| 28 | +""" |
| 29 | + gethead(x) |
| 30 | +
|
| 31 | +If `x` is a term as defined by `isterm(x)`, `gethead(x)` returns the |
| 32 | +head of the term if `x` represents a function call, for example, the head |
| 33 | +is the function being called. |
| 34 | +""" |
5 | 35 | function gethead end
|
| 36 | + |
| 37 | +""" |
| 38 | + getargs(x) |
| 39 | +
|
| 40 | +Get the arguments of `x`, must be defined if `isterm(x)` is `true`. |
| 41 | +""" |
6 | 42 | function getargs end
|
7 |
| -function metadata end |
| 43 | + |
| 44 | +""" |
| 45 | + metadata(x) |
| 46 | +
|
| 47 | +Return the metadata attached to `x`. |
| 48 | +""" |
| 49 | +metadata(x) = nothing |
| 50 | + |
| 51 | +""" |
| 52 | + metadata(x, md) |
| 53 | +
|
| 54 | +Returns a new term which has the structure of `x` but also has |
| 55 | +the metadata `md` attached to it. |
| 56 | +""" |
| 57 | +function metadata(x, data) |
| 58 | + error("Setting metadata on $x is not possible") |
| 59 | +end |
| 60 | + |
| 61 | + |
| 62 | +""" |
| 63 | + similarterm(x, head, args, type; metadata=nothing) |
| 64 | +
|
| 65 | +Returns a term that is in the same closure of types as `typeof(x)`, |
| 66 | +with `head` as the head and `args` as the arguments, `type` as the symtype |
| 67 | +and `metadata` as the metadata. By default this will execute `head(args...)` |
| 68 | +""" |
| 69 | +similarterm(x, head, args, type; metadata=nothing) = head(args...) |
8 | 70 |
|
9 | 71 | end # module
|
0 commit comments