<?xml version="1.0" encoding="UTF-8"?>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="exists" xml:lang="en">
    <refnamediv>
        <refname>exists</refname>
        <refpurpose>checks variable existence</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            ve = exists(name)
            ve = exists(name, where)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>name</term>
                <listitem>
                    <para>matrix of character strings: names of queried variables.</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>where</term>
                <listitem>
                    <para>an optional character with possible values:
                        <literal>'l'</literal> (local), <literal>'n'</literal>
                        (nolocal) and <literal>'a'</literal> (all). The default
                        value is <literal>'a'</literal>.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>ve</term>
                <listitem>
                    <para>
                        a matrix with the same size as <varname>name</varname> with possible values:
                        <literal>1</literal> if true,
                        <literal>0</literal> if false
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            <literal>exists(name)</literal> returns <literal>1</literal> if the
            variable named <literal>name</literal> exists and <literal>0</literal>
            otherwise.
        </para>
        <para>
            Caveats: a function which uses <literal>exists</literal> may return
            a result which depends on the environment!
        </para>
        <para>
            <literal>exists(name,'l')</literal> returns <literal>1</literal>
            if the variable named <literal>name</literal> exists in the environment of
            the current function and <literal>0</literal> otherwise.
        </para>
        <para>
            <literal>exists(name,'n')</literal> returns
            <literal>1</literal> if the variable named <literal>name</literal> exists
            in any level of the calling environment (including the Scilab shell main level) of the current function and
            <literal>0</literal> otherwise.
        </para>
        <para>
            <warning>
                Warning: the <literal>exists</literal> function does not check if a variable exists in
                the <link linkend="global">global</link> namespace.
            </warning>
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
exists("myNotLikelyToExistVar")
myNotLikelyToExistVar = 1;
exists("myNotLikelyToExistVar")
 ]]></programlisting>
        <programlisting role="example"><![CDATA[
deff('foo(x)',..
['disp([exists(''a12''),exists(''a12'',''l'')])'
 'disp([exists(''x''),exists(''x'',''l'')])'])
foo(1)
a12=[];foo(1)

function level1()
  function level2()
    disp(exists(["a","b"],"a"));
    disp(exists(["a","b"],"l"));
    disp(exists(["a","b"],"n"));
  endfunction
  level2()
endfunction
function go()
  a=1;
  level1()
endfunction
go()
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="isdef">isdef</link>
            </member>
            <member>
                <link linkend="isglobal">isglobal</link>
            </member>
            <member>
                <link linkend="whereis">whereis</link>
            </member>
            <member>
                <link linkend="type">type</link>
            </member>
            <member>
                <link linkend="typeof">typeof</link>
            </member>
            <member>
                <link linkend="macrovar">macrovar</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
