* Bug 15859 fixed: isempty() overloadable for tlists & mlists 03/20603/4
Samuel GOUGEON [Wed, 31 Oct 2018 16:43:10 +0000 (17:43 +0100)]
  http://bugzilla.scilab.org/15859

Change-Id: Ib7c5dc009b9f39829593ef2f399aa7448031532f

scilab/CHANGES.md
scilab/modules/elementary_functions/help/en_US/isempty.xml
scilab/modules/elementary_functions/help/ja_JP/isempty.xml
scilab/modules/elementary_functions/help/pt_BR/isempty.xml
scilab/modules/elementary_functions/help/ru_RU/isempty.xml
scilab/modules/elementary_functions/macros/isempty.sci
scilab/modules/elementary_functions/tests/unit_tests/isempty.dia.ref [deleted file]
scilab/modules/elementary_functions/tests/unit_tests/isempty.tst

index fb4916d..9a3af75 100644 (file)
@@ -672,6 +672,7 @@ Known issues
 * [#15853](http://bugzilla.scilab.org/show_bug.cgi?id=15853): `mlist("cblock")` displayed endlessly "operation +: Warning adding..."
 * [#15854](http://bugzilla.scilab.org/show_bug.cgi?id=15854): `horner(1:$,4)` yielded an error. Extractions from `cblock` tables were impacted.
 * [#15858](http://bugzilla.scilab.org/show_bug.cgi?id=15858): `size(cblock,'r'|'c'|'*'|1|2)` did not take the option into account. `size()` of an empty cblock table yielded an error.
+* [#15859](http://bugzilla.scilab.org/show_bug.cgi?id=15859): `isempty` could not be overloaded for custom mlist or tlist typeof.
 * [#15878](http://bugzilla.scilab.org/show_bug.cgi?id=15878): `sgrid` and `evans` were broken.
 * [#15880](http://bugzilla.scilab.org/show_bug.cgi?id=15880): `sgrid` needed some improvements: Labeling was sometimes ambiguous ; large circles were not labeled ; data_bounds did not always take the input wn into account ; named and #RRGGBB colors specifications could not be used. `evans` needed some improvements: the block of legends hid data ; asymptotes were too visible.
 * [#15886](http://bugzilla.scilab.org/show_bug.cgi?id=15886): Display of polynomials was broken.
index dea155f..0f5b71d 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2018 - 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.
  * 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:ns5="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="isempty" xml:lang="en">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="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="isempty" xml:lang="en">
     <refnamediv>
         <refname>isempty</refname>
         <refpurpose>check if a variable is an empty matrix or an empty
             <literal>isempty(x)</literal> returns true if <literal>x</literal> is an empty matrix
             or an empty list.
         </para>
+        <para>
+          <note>
+            isempty() can be overloaded for custom t-lists and m-lists typeof.
+          </note>
+        </para>
     </refsection>
     <refsection>
         <title>Examples</title>
@@ -56,4 +64,32 @@ isempty(a(2:$))
 isempty(find(rand(1:10)==5))
  ]]></programlisting>
     </refsection>
+    <refsection role="see also">
+        <title>See also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="empty">[]</link>
+            </member>
+            <member>
+                <link linkend="emptystr">emptystr</link>
+            </member>
+            <member>
+                <link linkend="size">size</link>
+            </member>
+            <member>
+                <link linkend="length">length</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    isempty() can now be overloaded for custom tlist and mlist typeof.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index a933770..0132a00 100644 (file)
@@ -3,8 +3,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2018 - 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.
  *
  -->
 
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="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="isempty" xml:lang="ja">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="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="isempty" xml:lang="ja">
 
     <refnamediv>
 
             空のリストの場合に真を返します.
 
         </para>
+        <para>
+          <note>
+            isempty() can be overloaded for custom t-lists and m-lists typeof.
+          </note>
+        </para>
 
     </refsection>
 
@@ -92,6 +100,34 @@ isempty(find(rand(1:10)==5))
  ]]></programlisting>
 
     </refsection>
+    <refsection role="see also">
+        <title>参照</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="empty">[]</link>
+            </member>
+            <member>
+                <link linkend="emptystr">emptystr</link>
+            </member>
+            <member>
+                <link linkend="size">size</link>
+            </member>
+            <member>
+                <link linkend="length">length</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>履歴</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    isempty() can now be overloaded for custom tlist and mlist typeof.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 
 </refentry>
 
index df56cab..b13fc80 100644 (file)
@@ -1,9 +1,9 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2018 - 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.
  * 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:ns4="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="isempty" xml:lang="pt">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="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="isempty" xml:lang="pt">
     <refnamediv>
         <refname>isempty</refname>
-        <refpurpose>verifica se uma variável é uma matriz vazia ou uma lista
+        <refpurpose>verifica se uma variável é uma matriz vazia ou uma lista
             vazia
         </refpurpose>
     </refnamediv>
     <refsynopsisdiv>
-        <title>Seqüência de Chamamento</title>
+        <title>Seqüência de Chamamento</title>
         <synopsis>t=isempty(x)</synopsis>
     </refsynopsisdiv>
     <refsection>
-        <title>Parâmetros</title>
+        <title>Parâmetros</title>
         <variablelist>
             <varlistentry>
                 <term>x</term>
         </variablelist>
     </refsection>
     <refsection>
-        <title>Descrição</title>
+        <title>Descrição</title>
         <para>
-            <literal>isempty(x)</literal> retorna 'true' (verdadeiro) se x é uma
+            <literal>isempty(x)</literal> retorna 'true' (verdadeiro) se x é uma
             matriz vazia ou uma lista vazia.
         </para>
+        <para>
+          <note>
+            isempty() can be overloaded for custom t-lists and m-lists typeof.
+          </note>
+        </para>
     </refsection>
     <refsection>
         <title>Exemplos</title>
@@ -56,4 +64,32 @@ isempty(a(2:$))
 isempty(find(rand(1:10)==5))
  ]]></programlisting>
     </refsection>
+    <refsection role="see also">
+        <title>Ver também</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="empty">[]</link>
+            </member>
+            <member>
+                <link linkend="emptystr">emptystr</link>
+            </member>
+            <member>
+                <link linkend="size">size</link>
+            </member>
+            <member>
+                <link linkend="length">length</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>Histórico</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    isempty() can now be overloaded for custom tlist and mlist typeof.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index a659b69..364abea 100644 (file)
@@ -2,8 +2,8 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2018 - 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.
  * 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:ns5="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="isempty" xml:lang="ru">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="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="isempty" xml:lang="ru">
     <refnamediv>
         <refname>isempty</refname>
         <refpurpose>
             <literal>isempty(x)</literal> возвращает значение "истина", если
             <literal>x</literal> является пустой матрицей или пустым списком.
         </para>
+        <para>
+          <note>
+            <literal>isempty()</literal> может быть перегружена для типов пользовательских типизированных
+            и матричноориентированных списков.
+          </note>
+        </para>
     </refsection>
     <refsection>
         <title>Примеры</title>
@@ -56,4 +65,33 @@ isempty(a(2:$))
 isempty(find(rand(1:10)==5))
  ]]></programlisting>
     </refsection>
+    <refsection role="see also">
+        <title>Смотрите также</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="empty">[]</link>
+            </member>
+            <member>
+                <link linkend="emptystr">emptystr</link>
+            </member>
+            <member>
+                <link linkend="size">size</link>
+            </member>
+            <member>
+                <link linkend="length">length</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>История</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0.2</revnumber>
+                <revdescription>
+                    isempty() теперь может быть перегружена для типов пользовательских типизированных
+                    и матричноориентированных списков.
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 98823ff..9d4ec95 100644 (file)
@@ -1,9 +1,8 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 1998 - INRIA
 // Copyright (C) DIGITEO - 2011-2012 - Allan CORNET
-// Copyright (C) 2016 - Samuel GOUGEON
-//
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2016, 2018 - 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.
@@ -49,6 +48,11 @@ function answ = isempty(m)
         if typeof(m) == "rational" then
             answ = size(m, "*") == 0;
         else
+            oname = "%" + typeof(m) + "_isempty"
+            if isdef(oname,"n")
+                execstr("answ = "+oname+"(m)")
+                return
+            end
             answ = %t;
             for i = 2:size(m)
                 answ = answ & (type(m(i))==0 || isempty(m(i)))
@@ -85,6 +89,11 @@ function answ = isempty(m)
                 end
             end
         else                    // other types of mlist
+            oname = "%" + typeof(m) + "_isempty"
+            if isdef(oname,"n")
+                execstr("answ = "+oname+"(m)")
+                return
+            end
             answ = %f
         end
 
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/isempty.dia.ref b/scilab/modules/elementary_functions/tests/unit_tests/isempty.dia.ref
deleted file mode 100644 (file)
index 39359f5..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// =============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
-// Copyright (C) 2016 - Samuel GOUGEON
-//
-//  This file is distributed under the same license as the Scilab package.
-// =============================================================================
-// <-- CLI SHELL MODE -->
-// unit tests for isempty function
-// =============================================================================
-// empty matrix
-assert_checktrue(isempty([]));
-// character string
-assert_checktrue(isempty(''));
-// matrix of character string
-assert_checktrue(isempty([ '' , '' ; '' , '' ]));
-assert_checkfalse(isempty([ ' ' , '' ; '' , '' ]));
-// empty list
-assert_checktrue(isempty(list()));
-// list with only undefined elements
-assert_checktrue(isempty(list(,)));
-// empty structure()
-assert_checktrue(isempty(struct()));
-// empty cell()
-assert_checktrue(isempty({}));
-// nested empty containers
-assert_checktrue(isempty(list({}, list("",,[]), [], struct())));
-s.r = [];
-s.c = {};
-s.L = list();
-s.s = struct();
-assert_checktrue(isempty(s));
-// other mlists are never empty
-assert_checkfalse(isempty(mlist('')));
index f0deff3..3ba4486 100644 (file)
@@ -1,12 +1,13 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
-// Copyright (C) 2016 - Samuel GOUGEON
+// Copyright (C) 2016, 2018 - Samuel GOUGEON
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 // <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
 
 // unit tests for isempty function
 // =============================================================================
@@ -41,5 +42,14 @@ s.L = list();
 s.s = struct();
 assert_checktrue(isempty(s));
 
+// existing overloads
+t = tlist("abc");
+function r = %abc_isempty(L)
+    r = "%abc_isempty called"
+endfunction
+assert_checkequal(isempty(t), "%abc_isempty called");
+t = mlist("abc");
+assert_checkequal(isempty(t), "%abc_isempty called");
+
 // other mlists are never empty
 assert_checkfalse(isempty(mlist('')));