Skip to content

Commit

Permalink
Merge pull request #234 from control-toolbox/206-improve-def
Browse files Browse the repository at this point in the history
escaped new @def
  • Loading branch information
jbcaillau authored Aug 10, 2024
2 parents 2c0086d + fcca844 commit 2451235
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/onepass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,11 @@ end true # final boolean to show parsing log
"""
macro def(e)
ocp = gensym()
quote
code = quote
@def $ocp $e
$ocp
end
esc(code)
end

macro def(ocp, e, log=false)
Expand Down
36 changes: 30 additions & 6 deletions test/test_onepass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ function test_onepass()

# ---------------------------------------------------------------
# ---------------------------------------------------------------
@testset "log" begin
println("o = @def syntax + log testset...")
@testset "@def o syntax" begin
println("@def o syntax testset...")

oo = @def begin
λ R^2, variable
Expand All @@ -15,6 +15,29 @@ function test_onepass()
@test oo.initial_time == 0
@test oo.final_time == Index(2)

a = 1
f(b) = begin # closure of a, local c, and @def in function
c = 3
ocp = @def begin
t [ a, b ], time
x R, state
u R, control
(t) == x(t) + u(t) + b + c + d
end
return ocp
end
b = 2
o = f(b)
d = 4
x = 10
u = 20
@test o.dynamics(x, u) == x + u + b + 3 + d

end

@testset "log" begin
println("log testset...")

@def o begin
λ R^2, variable
tf = λ₂
Expand Down Expand Up @@ -2291,13 +2314,14 @@ end
u R, control
(t) == x(t) + u(t) + b + c + d
end
ocp
return ocp
end
o = f(2)
b = 2
o = f(b)
d = 4
x = 10
u = 20
@test o.dynamics(x, u) == x + u + 2 + 3 + 4
@test o.dynamics(x, u) == x + u + b + 3 + d

end

Expand Down Expand Up @@ -2368,4 +2392,4 @@ end

end

end
end

0 comments on commit 2451235

Please sign in to comment.