Skip to content

Commit 2e8a6b6

Browse files
committed
feat!: force StructuredExpression construction to be done with kwarg
1 parent d931c69 commit 2e8a6b6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/StructuredExpression.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ kws = (;
3737
f = parse_expression(:(x * x - cos(2.5f0 * y + -0.5f0)); kws...)
3838
g = parse_expression(:(exp(-(y * y))); kws...)
3939
40-
f_plus_g = StructuredExpression((; f, g), nt -> nt.f + nt.g)
40+
f_plus_g = StructuredExpression((; f, g); structure=nt -> nt.f + nt.g)
4141
```
4242
4343
Now, when evaluating `f_plus_g`, this expression type will
@@ -83,8 +83,8 @@ struct StructuredExpression{
8383
end
8484

8585
function StructuredExpression(
86-
trees::NamedTuple,
87-
structure::F;
86+
trees::NamedTuple;
87+
structure::F,
8888
operators::Union{AbstractOperatorEnum,Nothing}=nothing,
8989
variable_names::Union{AbstractVector{<:AbstractString},Nothing}=nothing,
9090
extra...,

test/test_structured_expression.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
shower(ex) = sprint((io, e) -> show(io, MIME"text/plain"(), e), ex)
1313

14-
f_plus_g = StructuredExpression((; f, g), nt -> nt.f + nt.g)
15-
f_div_g = StructuredExpression((; f, g), nt -> nt.f / nt.g)
16-
cos_f = StructuredExpression((; f), nt -> cos(nt.f))
17-
exp_g = StructuredExpression((; g), nt -> exp(nt.g))
14+
f_plus_g = StructuredExpression((; f, g); structure=nt -> nt.f + nt.g)
15+
f_div_g = StructuredExpression((; f, g); structure=nt -> nt.f / nt.g)
16+
cos_f = StructuredExpression((; f); structure=nt -> cos(nt.f))
17+
exp_g = StructuredExpression((; g); structure=nt -> exp(nt.g))
1818

1919
@test shower(f_plus_g) == "((x * x) - cos((2.5 * y) + -0.5)) + exp(-(y * y))"
2020
@test shower(f_div_g) == "((x * x) - cos((2.5 * y) + -0.5)) / exp(-(y * y))"
@@ -43,7 +43,7 @@ end
4343
f = parse_expression(:(x * x - cos(2.5f0 * y + -0.5f0)); kws...)
4444
g = parse_expression(:(exp(-(y * y))); kws...)
4545

46-
ex = StructuredExpression((; f, g), nt -> nt.f + nt.g)
46+
ex = StructuredExpression((; f, g); structure=nt -> nt.f + nt.g)
4747

4848
@test test(ExpressionInterface, StructuredExpression, [ex])
4949
end
@@ -64,7 +64,7 @@ end
6464
g = parse_expression(:(exp(-(y * y))); kws...)
6565

6666
c = [1]
67-
ex = StructuredExpression((; f, g), my_factory; a=c)
67+
ex = StructuredExpression((; f, g); structure=my_factory, a=c)
6868

6969
@test ex.metadata.extra.a[] == 1
7070
@test ex.metadata.extra.a === c
@@ -114,7 +114,7 @@ end
114114
This is a composite `AbstractExpression` object that composes multiple
115115
expressions during evaluation.
116116
=#
117-
ex = StructuredExpression((; f, g), nt -> nt.f + nt.g; operators, variable_names)
117+
ex = StructuredExpression((; f, g); structure=nt -> nt.f + nt.g, operators, variable_names)
118118
ex
119119
@test typeof(ex) <: AbstractExpression{Float64,<:Node{Float64}} #src
120120
#=

0 commit comments

Comments
 (0)