@@ -7,6 +7,7 @@ Returns `true` if `x` is a term. If true, `gethead`, `getargs`
7
7
must also be defined for `x` appropriately.
8
8
"""
9
9
isterm (x) = false
10
+ isterm (x:: Type{Expr} ) = true
10
11
11
12
"""
12
13
symtype(x)
@@ -33,13 +34,22 @@ head of the term if `x` represents a function call, for example, the head
33
34
is the function being called.
34
35
"""
35
36
function gethead end
37
+ gethead (e:: Expr ) = e. head
36
38
37
39
"""
38
40
getargs(x)
39
41
40
42
Get the arguments of `x`, must be defined if `isterm(x)` is `true`.
41
43
"""
42
- function getargs end
44
+ getargs (e:: Expr ) = e. args
45
+
46
+ """
47
+ arity(x)
48
+
49
+ Returns the number of arguments of `x`. Implicitly defined
50
+ if `getargs(x)` is defined.
51
+ """
52
+ arity (x) = length (getargs (x))
43
53
44
54
"""
45
55
metadata(x)
64
74
65
75
Returns a term that is in the same closure of types as `typeof(x)`,
66
76
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...)`
77
+ and `metadata` as the metadata. By default this will execute `head(args...)`.
78
+ `x` parameter can also be a `Type`.
68
79
"""
69
- similarterm (x, head, args, type; metadata= nothing ) = head (args... )
80
+ similarterm (x, head, args; type= nothing , metadata= nothing ) = head (args... )
81
+ similarterm (x:: Type{Expr} , head, args; type= nothing , metadata= nothing ) = Expr (head, args... )
70
82
71
83
end # module
84
+
0 commit comments