<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2006-2008 - INRIA
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 * Copyright (C) 2020 - Samuel GOUGEON
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg" xmlns:db="http://docbook.org/ns/docbook"
          xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="setfield">
    <refnamediv>
        <refname>setfield</refname>
        <refpurpose>mlist, tlist, またはlistの要素の値を変更する</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>呼び出し手順</title>
        <synopsis>uL = setfield(a, v, L)</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>パラメータ</title>
        <variablelist>
            <varlistentry>
                <term>L</term>
                <listitem>
                    <literal>list</literal>, <literal>tlist</literal>,
                    または<literal>mlist</literal>リスト：コンポーネントを変更する必要があるリスト.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>a</term>
                <listitem>
                    変更するコンポーネントのアドレス. 文字列として指定されたフィールド名,
                    または正の整数として指定されたインデックスのいずれかになります.
                    詳細については, <link linkend="insertion">insertion</link>をご覧ください.
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>v</term>
                <listitem>
                    任意のScilabオブジェクト：割り当てる値
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>uL</term>
                <listitem>
                    更新されたリスト
                    <para/>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>説明</title>
        <para>
            <literal>L=setfield(a,v,L)</literal> addresses and changes the
            i<superscript>th</superscript> element of a list, in a unified way
            over lists, tlists and mlists.
        </para>
        <para>
            For simple lists and for tlists, <literal>L=setfield(a,v,L)</literal>
            is equivalent to <literal>L(a)=v</literal>, that is simpler and should be preferred.
            The same stands for any mlist if the address <varname>a</varname> is a
            field's name.
        </para>
        <para>
            However, for any mlist L, if <literal>i</literal> is an index, the insertion
            <literal>L(i)=v</literal> is not predefined, in order to let the user define
            an overload implementing a matrix-oriented insertion, if required.
            Yet <literal>setfield(i,v,L)</literal> is always defined, with the same meaning as
            for other list and tlist types.
        </para>
    </refsection>
    <refsection>
        <title>例</title>
        <para>
            For a tlist, <literal>setfield(3, v, T)</literal> is equivalent to
            <literal>T(3)=v</literal> :
        </para>
        <programlisting role="example"><![CDATA[
T = tlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
// The insertion is predefined:
T(3) = [%t %t %f];
T(3)

T = setfield(3, [%f %t %f], T);
T(3)
 ]]></programlisting>
    <screen><![CDATA[
--> T = tlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
--> // The insertion is predefined:
--> T(3) = [%t %t %f];
--> T(3)
 ans  =
  T T F

--> T = setfield(3, [%f %t %f], T);
--> T(3)
 ans  =
  F T F
]]></screen>
        <para>
            For a mlist, there is no predefined indexed insertion routine, to let
             the user define a matrix-oriented insertion overload if required.
        </para>
        <programlisting role="example"><![CDATA[
M = mlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
M.b = [%t %t %t];
M.b                 // OK, while ...
M(3) = [%f %t %f];  // => error

// But a raw direct insertion with setfield() is always possible:
M = setfield(3, [%t %f %t], M);
getfield(3, M)
 ]]></programlisting>
    <screen><![CDATA[
--> M = mlist(['V','a','b'], [%z (1-%z) %z^2], [%f %t %t]);
--> M.b = [%t %t %t];
--> M.b                 // OK, while ...
 ans  =
  T T T

--> M(3) = [%f %t %f];  // => error
Function not defined for given argument type(s),
  check arguments or define function %b_i_V for overloading.

--> // But a raw direct insertion with setfield() is always possible:
--> M = setfield(3, [%t %f %t], M);
--> getfield(3, M)
 ans  =
  T F T
]]></screen>
    </refsection>
    <refsection role="see also">
        <title>参照</title>
        <simplelist type="inline">
            <member>
                <link linkend="insertion">insertion</link>
            </member>
            <member>
                <link linkend="getfield">getfield</link>
            </member>
        </simplelist>
    </refsection>
    <refsection>
        <title>履歴</title>
        <revhistory>
            <revision>
                <revnumber>6.0.0</revnumber>
                <revdescription>
                    <itemizedlist>
                        <listitem>
                            The updated list is now returned, instead of being changed "in place".
                        </listitem>
                        <listitem>
                            setfield() can no longer be used for cells arrays.
                        </listitem>
                    </itemizedlist>
                </revdescription>
            </revision>
        </revhistory>
    </refsection>
</refentry>
