I want to change the field types of R to be of StaticArray. However, I am having the below error. Could you please help me to solve this issue?
using LinearAlgebra, StaticArrays
Base.@kwdef mutable struct Rs
I::Vector{Float64} = [1,2,3]
Dot::Array{Float64, 2} = [1 1 1; 2 2 2; 3 3 3]
end
Base.@kwdef mutable struct S_Rs
I::MVector{3,Float64}
Dot::MMatrix{3,3,Float64,9}
end
function all()
R = Rs[];
push!(R, Rs());
push!(R, Rs());
@eval Main.S_Rs(a::Main.Rs) = Main.S_Rs($([:(a.$x) for x in fieldnames(Main.Rs)]...))
R = Main.S_Rs.(R);
end
R = all();
ERROR: MethodError: no method matching S_Rs(::Rs)
The applicable method may be too new: running in world age 32331, while current world is 32332.
Thank you very much. Yes, it works. There is a small issue that when I run it, it always print R in the REPL (as below) although I have ; at the end of each line. I do not know why and is there a way to stop printing it?
I’m guessing you’re doing include("file.jl") at the REPL? Semicolons aren’t needed to avoid printing the output of each line. Rather, it’s only things you write at the REPL that will show their result unless there’s a final ;. Having semicolons inside that file.jl will have no effect; but if you don’t want to see the result of the final expression when including it, you put the semicolon after the include("file.jl"); at the REPL.
Just add one line containing nothing at the end of the included file, so that the value returned to the REPL is nothing (which is not displayed by the REPL) ?