Use macros as a DSL to create state machine
Just saw this on METADATA.jl, cool idea. It'd be need to use macros to make the state machine, something like:
@build_state_machine fsm
"initial" => "first"
"events" => [
"name" => "hop"
...
"final" => "fourth"
end
anything thats parseable by Julia will work, doesn't have to be valid Julia syntax. Just a thought :)
Cool idea! I was just thinking how the Dict{String,String} and (String=>Any) syntax is a bit awkward, in the context of "just sketch a map of your FSM here". (Or, I could settle for Dict{Any,Any}, and gain a nice Python-style syntax...)
Yeah why do you need the types?
Or maybe deeper, why index by strings at all? It'd more Julia to use symbols, e.g.
julia> fsm = state_machine([
:initial => :first,
:final => :fourth,
:events => [
[
:name => :hop,
:from => :first,
:to => :second,
],
[
:name => :skip,
:from => :second,
:to => :third,
],
[
:name => :jump,
:from => :third,
:to => :fourth,
],
],
:callbacks => [
:onbeforeevent => (fsm::StateMachine, args...) -> 10,
],
])
With macros you could even get away without the :, I think... Check out https://github.com/JuliaOpt/JuMP.jl for inspiration, we kinda have a DSL going there
I removed the type info for a nicer-looking syntax. Leaving this open for now though, as I do find the idea of a DSL to be very appealing, just don't quite have the focus to write it right now :)