[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug with struct, setfield
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: Bug with struct, setfield |
Date: |
Wed, 23 May 2012 17:11:27 -0400 |
On 22 May 2012 11:58, Jacob Eggers <address@hidden> wrote:
> Has anyone else seen this bug with setfield? It seems to work properly, but
> when I check if the field is set with isfield, it does not work.
>
>> octave> s = struct()
>> s =
>> scalar structure containing the fields:
>>
>> octave> setfield(s, 'f1', 1)
>> ans =
>> scalar structure containing the fields:
>> f1 = 1
>> octave> isfield(s, 'f1')
>> ans = 0
This isn't a bug.
Octave doesn't have reference semantics. When you use setfield, you
obtain a copy of the input struct s with whatever modification you've
done. If you want to use setfield *and* modify the struct, you have to
do
s = setfield(s, ...)
HTH,
- Jordi G. H.