-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New syntax to replace {} #6
Comments
I favor Option 2 slightly, as it would permit equality syntax. I don't On Sat, Dec 27, 2014 at 12:37 PM, Tom Short notifications@github.com
|
Here's a first cut at code to implement both options: using Sims
macro equations(args)
esc(equations_helper(args))
end
function parse_args(a::Expr)
if a.head == :line
nothing
elseif a.head == :(=)
Expr(:call, :-, parse_args(a.args[1]), parse_args(a.args[2]))
else
Expr(a.head, [parse_args(x) for x in a.args]...)
end
end
parse_args(a::Array) = [parse_args(x) for x in a]
parse_args(x) = x
function equations_helper(arg)
Expr(:ref, :Equation, parse_args(arg.args)...)
end
Equation = Any
function Vanderpol1()
y = Unknown(1.0, "y")
x = Unknown("x")
Equation[
der(x, -1.0) - ((1 - y^2) * x - y)
der(y) - x
]
end
v1 = sim(Vanderpol)
function Vanderpol2()
y = Unknown(1.0, "y")
x = Unknown("x")
@equations begin
der(x, -1.0) = (1 - y^2) * x - y
der(y) = x
end
end
v1 = sim(Vanderpol1())
v2 = sim(Vanderpol2()) It needs a bit more error checking. Edit: fix issue spotted by @iraikov. |
I had to remove a spurious '=' after 'function parse_args (a::Expr)' but On Sun, Dec 28, 2014 at 5:37 AM, Tom Short notifications@github.com wrote:
|
For error checking, we probably need to check that there is a begin construct. Also, we might also want to support one liners. I don't think that works now. |
Hi Tom, I have extended the definition of equations_helper to check that its
end On Sun, Dec 28, 2014 at 4:38 PM, Tom Short notifications@github.com wrote:
|
Actually, I just realized I forgot to convert the examples to the new On Thu, Jan 1, 2015 at 5:32 PM, Tom Short notifications@github.com wrote:
|
Okay, reopening... |
I'll go through the standard library and convert to one of these. Any preference? |
I was just looking at the vanderpol and vanderpol_with_events examples, and When I replace {} with @equations begin .. end in vanderpol_with_events, Anyway, to answer your question, I prefer @equations for systems with On Thu, Jan 1, 2015 at 6:25 PM, Tom Short notifications@github.com wrote:
|
I'm not surprised on the macro, but I am on the Equation[]. Hmm... |
I stand corrected, Equations[] works, I had just forgotten the commas... I On Thu, Jan 1, 2015 at 7:02 PM, Tom Short notifications@github.com wrote:
|
I'll take a look tomorrow. Also, you shouldn't need commas... |
If you can also look at Event, it seems to rely on the {} syntax so it On Thu, Jan 1, 2015 at 7:05 PM, Tom Short notifications@github.com wrote:
|
I've gotten the examples converted. I'll work on stdlib now. |
@iraikov, this should be done, but please check your examples. There's a chance that I goofed parens accidentally. |
Hi Tom, All of the neural examples work, except for the only one that has https://github.com/tshort/Sims.jl/blob/master/examples/neural/iafrefr.jl It seems that the trefr constant, computed on line 57 is somehow not
On Sat, Jan 3, 2015 at 5:26 AM, Tom Short notifications@github.com wrote:
|
I don't think that should have worked. |
Thanks for looking at this. Of course, I would be happy with different On Sat, Jan 3, 2015 at 4:19 PM, Tom Short notifications@github.com wrote:
|
I think I fixed the |
Works like a charm, thanks a lot! On Sat, Jan 3, 2015 at 7:23 PM, Tom Short notifications@github.com wrote:
|
Because curly brackets are going away (JuliaLang/julia#8578), we need something else. Two options I can think of are:
Option 1
or
This is the easiest change. We'd just need to set
Equations = Any
.Option 2
This has the advantage that we write the macro to allow
=
in model equations. We could support either or both of these.Here are options I don't think will work:
-
@model { ... }
-- Curly brackets are depreciated in the parser, so macros don't help us avoid that.-
[ ... ]
-- usesvcat
The text was updated successfully, but these errors were encountered: