Difference between revisions of "Manual:DIL Manual/integerlist"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
 
= integerlist =
 
= integerlist =
−
'''Type.''' The keyword is <code>intlist</code>.
+
'''Type.''' Another name used on this wiki for [[Manual:DIL Manual/intlist|intlist]].
  
−
il : intlist;
+
DIL has no keyword <code>integerlist</code>: a list of integers is declared with <code>intlist</code>.
  
−
A list of integers, numbered from 0. Declare it as <code>intlist</code> (there is no keyword <code>integerlist</code>). The <code>vals</code> field of an extra description is also an intlist, and so is what <code>weapon_info()</code> gives.
+
var
 +
    il : intlist;
  
−
== Using it ==
+
See [[Manual:DIL Manual/intlist|intlist]].
−
{| class="wikitable"
 
−
! Write !! What it does
 
−
|-
 
−
| <code>il := {10, 20, 30};</code> || sets the whole list; the values must be constants or macros, not variables
 
−
|-
 
−
| <code>il.[1]</code> || the second value; read and write
 
−
|-
 
−
| <code>length(il)</code> || how many values it has
 
−
|-
 
−
| <code>insert(il, i, v);</code> || puts <code>v</code> in at position <code>i</code>, moving the rest up; <code>i</code> from 0 to <code>length(il)</code>
 
−
|-
 
−
| <code>remove(il, i);</code> || takes out the value at position <code>i</code>
 
−
|-
 
−
| <code>il := null;</code> || empties it
 
−
|-
 
−
| <code>il := other;</code> || copies another intlist
 
−
|}
 
−
 
 
−
== Notes ==
 
−
* An index outside the list fails: reading <code>il.[5]</code> of a list of three is a failed value (false in every comparison), and assigning to it does nothing. The list doesn't grow by assignment; add values with <code>insert(il, length(il), v)</code>.
 
−
* <code>insert()</code> with a position past the end, and <code>remove()</code> with one outside the list, do nothing.
 
−
* A new intlist variable is empty. Unlike unit and extra variables, an intlist keeps its values across <code>wait()</code> and <code>pause</code>.
 
−
* <code>in</code> doesn't work on intlists; walk the list with a <code>while</code> loop.
 
−
* <code>{...}</code> can't hold variables: <code>{n, 2}</code> is a syntax error. Build such a list with <code>insert()</code>.
 
−
* An intlist can be a template's argument; from a zone file it's written <code>{1, 2, 3}</code>. <code>dilcopy()</code> from DIL can't pass lists.
 
−
 
 
−
== Example ==
 
−
<pre>
 
−
dilbegin integer sumlist(il : intlist);
 
−
var
 
−
  i : integer;
 
−
  sum : integer;
 
−
code
 
−
{
 
−
  i := 0;
 
−
  sum := 0;
 
−
  while (i < length(il))
 
−
  {
 
−
      sum := sum + il.[i];
 
−
      i := i + 1;
 
−
  }
 
−
  return (sum);
 
−
}
 
−
dilend
 
−
 
 
−
dilbegin listdemo();
 
−
external
 
−
  integer sumlist@ex(il : intlist);
 
−
var
 
−
  il : intlist;
 
−
  n : integer;
 
−
code
 
−
{
 
−
  il := {10, 20, 30};
 
−
  il.[1] := 25;
 
−
  insert(il, length(il), 40);
 
−
  remove(il, 0);
 
−
  n := sumlist@ex(il);
 
−
  log("Sum is " + itoa(n));
 
−
  il := null;
 
−
  quit;
 
−
}
 
−
dilend
 
−
</pre>
 
−
Builds the list 25, 30, 40 and logs "Sum is 95".
 
  
 
== See also ==
 
== See also ==
 
* [[Manual:DIL Manual/intlist|intlist]]
 
* [[Manual:DIL Manual/intlist|intlist]]
−
* [[Manual:DIL Manual/insert()|insert()]]
 
−
* [[Manual:DIL Manual/remove()|remove()]]
 
−
* [[Manual:DIL Manual/length()|length()]]
 
−
* [[Manual:DIL Manual/vals|vals]]
 
 
* [[Manual:DIL Manual/stringlist|stringlist]]
 
* [[Manual:DIL Manual/stringlist|stringlist]]
−
* [[Manual:DIL Manual/Data Types|Data Types]]
 

Latest revision as of 23:28, 14 November 2026

integerlist

Type. Another name used on this wiki for intlist.

DIL has no keyword integerlist: a list of integers is declared with intlist.

var
   il : intlist;

See intlist.

See also