Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - 日本語 -
Справка Scilab >> Data Structures > null

null

deletes a list component or a field of a structure, Mlist, or Tlist

Syntax

List(i) = null()
Struct.field = null()

Description

List being a simple list, List(i)=[] sets [] as the value of the ith component. Hence, [] can't be used with lists to remove some parts of the left-hand-side (LHS) object, as it can do it for regular vectors or arrays .

null() aims to do it. It generates an object of type 0 and typeof listdelete that deletes the object to which it is assigned.

The overloading code of listdelete objects is 0.
Assigning null() to a variable deletes it. However, using clear should be preferred to clear named objects.

Examples

type, typeof, and null overloading code:

type(null())
typeof(null())
null()==null()
--> type(null())
 ans  =
   0.

--> typeof(null())
 ans  =
 listdelete

--> null()==null()

Undefined operation for the given operands.
check or define function %0_o_0 for overloading.

Deletion of a list component:

L = list(1:10, "foo", %f, (1-%z)^2);
length(L)
L(2) = null();
length(L)
L(2)
--> length(L)
 ans  =
   4.

--> L(2) = null();

--> length(L)
 ans  =
   3.

--> L(2)
 ans  =
  F

Deletion of a field of a structure:

s(2,3).r = %pi;
s(2,1).p = (1-%z)^2;
s(1,2).b = %T
s.p = null()
--> s(2,3).r = %pi;
--> s(2,1).p = (1-%z)^2;
--> s(1,2).b = %T
 s  =
  2x3 struct array with fields:
    r
    p
    b

--> s.p = null()
 s  =
  2x3 struct array with fields:
    r
    b

Deletion of a field of a Mlist or Tlist: No default destructor is defined:

ML = mlist(["test" "b" "c" "rp" "t"],[%t %f], %i, 1+%s^2, ["abc" "de" "f"]);
fieldnames(ML)'
ML.rp
ML.rp = null()
--> fieldnames(ML)'
 ans  =
!b  c  rp  t  !

--> ML.rp
 ans  =
       2
   1 +s

--> ML.rp = null()

Function not defined for given argument type(s),
  check arguments or define function %0_i_test for overloading.
// Let's define a field destructor called by "= null()":

function L=%0_i_test(fieldName, Null, L)
    header = getfield(1,L)
    i = find(header==fieldName);
    if i~=[] then
        header(i) = [];
        L = setfield(1, header, L);
        L = setfield(i, null(), L);
    end
endfunction

// Let's use it:
ML.rp = null();
fieldnames(ML)'
ML.b, ML.c, ML.t
--> ML.rp = null();
--> fieldnames(ML)'
 ans  =
!b  c  t  !

--> ML.b, ML.c, ML.t
 ans  =
  T F

 ans  =
   i

 ans  =
!abc  de  f  !

See also

  • clear — уничтожает переменные
  • clearglobal — уничтожает глобальные переменные
  • [] — ([]) пустая матрица
  • delete — delete a graphic entity and its children.
  • xmlDelete — Delete a XML document
  • jremove — Remove a Java Object on the Java side
  • jnull — The Scilab version of the Java null object.
  • jvoid — For no argument functions
  • list — объект Scilab'а и функция определения списка
  • mlist — объект Scilab'а, определение матричноориентированного типизированного списка
  • tlist — объект Scilab'а и определение типизированного списка
  • struct — создаёт структуру
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:05:05 CET 2019