Agents constructor

Hi, I have two questions:
On the first hand, quite recent videos explaining the use showed a use of the @agents macro as

@agents NameAgentType GridAgent{2} begin
      someField
  end

And when I do this with this syntaxis it actually works. The docs instead say the way to go is

@agent struct YourAgentType{X}(AgentTypeToInherit) [<: OptionalSupertype]
    extra_property::X
    other_extra_property_with_default::Bool = true
    const other_extra_const_property::Int
    # etc...
end

And it says that it supports Julia mutable struct declaration but when I run

@agent mutable struct Client(NoSpaceAgent) 
    fieldA::Float64
end

It shows an error:

ERROR: LoadError: MethodError: no method matching namify(::Nothing)

Closest candidates are:
  namify(::Expr)
   @ MacroTools ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:132
  namify(::Symbol)
   @ MacroTools ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:131

Stacktrace:
 [1] compute_base_fields(base_type_spec::Nothing)
   @ Agents ~/.julia/packages/Agents/gV8cz/src/core/agents.jl:404
 [2] _agent(struct_repr::Expr)
   @ Agents ~/.julia/packages/Agents/gV8cz/src/core/agents.jl:206
 [3] var"@agent"(__source__::LineNumberNode, __module__::Module, struct_repr::Any)
   @ Agents ~/.julia/packages/Agents/gV8cz/src/core/agents.jl:200
in expression starting at /home/msanchezr/RevAIsor/ABM/sim.jl:44

Though it apparently works when I remove the “mutable” it haunts me that it supports a documented synthax but not one it says it does.

You’re looking at mismatched versions here between the tutorial, the docs, and your installed version. It looks like the tutorial is using v5, which matches what you currently have installed. But you’re looking at the docs for v6. Use the dropdown on the bottom left of the docs to pick the version you’re using — it might be: https://juliadynamics.github.io/Agents.jl/v5.17/tutorial/.

I guess saying it supports “any” declaration is probably not an accurate statement, as it doesn’t apply to mutable. Because it is already added by de facto. All @agent created types are mutable already, so you are trying to add an extra mutable and that doesn’t work. This should clarified in the docs (if it isn’t already?).

1 Like

as for your first question, we allowed (internally) the first version you posted to work for backwards compatibility. It is not supported in any official sense and may be removed in future versions without any warning.

@martin_sanchez this post here and the one you just opened about DynamicalSystems.jl are pretty much the same problem: attempting to use too old versions that use InteractiveDynamics.jl. Can I ask, where did you find the advice to use this? Probably some outdated tutorial that exists somewhere and needs to be deleted.

Yes, it seems like it. This one uses the outdated construction method:

And this one uses InteractiveDynamics:

Thanks. I currently have v6.0.15, but already read that this way of calling the macro can be delted without warning in future versions.

Oh well, I can’t affect either of these videos.

Videos cannot be updated to newer versions. My advice would be to not use videos to learn code. At least, not for the packages of JuliaDynamics. The documentation is as good as it can possible get, and always up to date. Start there!

1 Like

every documentation page has an edit button at the top right. It is super easy to contribute to documentation.