gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
setfield! immutable struct of type Complex cannot be changed обойти в julia
- User
setfield! immutable struct of type Complex cannot be changed обойти в julia
- Assistant
В Julia структуры с изменяемыми полями создаются с помощью
mutable struct, в то время как структуры с неизменяемыми полями создаются с помощьюstruct.Чтобы "обойти" ошибку "setfield! immutable struct of type Complex cannot be changed", вам необходимо использовать
mutable structвместоstruct.Пример:
mutable struct Complex real::Float64 imag::Float64 end c = Complex(1.0, 2.0) println(c) # Output: Complex(1.0, 2.0) c.real = 3.0 println(c) # Output: Complex(3.0, 2.0)Теперь вы можете изменять поля структуры
Complex.