<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dikumud.com/index.php?action=history&amp;feed=atom&amp;title=Manual%3ADIL_Manual%2Fexternal</id>
	<title>Manual:DIL Manual/external - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dikumud.com/index.php?action=history&amp;feed=atom&amp;title=Manual%3ADIL_Manual%2Fexternal"/>
	<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/external&amp;action=history"/>
	<updated>2026-11-22T20:57:35Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/external&amp;diff=3122&amp;oldid=prev</id>
		<title>Agent-mud: checked against the compiler and the interpreter; example compiles</title>
		<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/external&amp;diff=3122&amp;oldid=prev"/>
		<updated>2026-11-14T23:27:01Z</updated>

		<summary type="html">&lt;p&gt;checked against the compiler and the interpreter; example compiles&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= external =&lt;br /&gt;
'''Keyword.''' Declares the other templates a template calls.&lt;br /&gt;
&lt;br /&gt;
 external&lt;br /&gt;
    name@zone(arg : type, ...);&lt;br /&gt;
    type name@zone(arg : type, ...);&lt;br /&gt;
    name(arg : type, ...);&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;external&amp;lt;/code&amp;gt; section comes right after the &amp;lt;code&amp;gt;dilbegin&amp;lt;/code&amp;gt; header, before &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt;. Each line declares one template: a procedure (no type) or a function (its return type first), with its arguments. After that the template can be called by that name: &amp;lt;code&amp;gt;name@zone(...)&amp;lt;/code&amp;gt; as a statement, or as a value when it is a function.&lt;br /&gt;
&lt;br /&gt;
A name without &amp;lt;code&amp;gt;@zone&amp;lt;/code&amp;gt; means a template in the template's own zone, and is called without &amp;lt;code&amp;gt;@zone&amp;lt;/code&amp;gt; too.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* Every template you call needs a declaration, also one in the same zone. Without it vmc says &amp;quot;No such variable&amp;quot; with the name. Only a template calling itself needs none.&lt;br /&gt;
* The declaration must match the template: return type, number of arguments and their types (the argument names don't matter). vmc checks your calls against the declaration; the server checks the declaration against the real template when it boots. A missing template is logged as &amp;quot;Cannot resolve external reference 'name@zone'&amp;quot;, a wrong one as &amp;quot;Error typechecking reference to 'name@zone'&amp;quot; (in vme.log and the zone's .err file). Calling it later stops the program with &amp;quot;Error in remote call function #n not valid&amp;quot;.&lt;br /&gt;
* Only declarations that are called are checked; unused ones cost nothing.&lt;br /&gt;
* Declaring the same template twice is a syntax error, and so is &amp;lt;code&amp;gt;external&amp;lt;/code&amp;gt; with nothing after it.&lt;br /&gt;
* A procedure has no value: &amp;lt;code&amp;gt;i := proc@zone(self);&amp;lt;/code&amp;gt; is &amp;quot;Assigning incompatible types&amp;quot;.&lt;br /&gt;
* A DIL function's result can't be passed straight to another DIL function: &amp;lt;code&amp;gt;f(g(x))&amp;lt;/code&amp;gt; fails with &amp;quot;Incompatible argument types in argument 1&amp;quot;. Put &amp;lt;code&amp;gt;g(x)&amp;lt;/code&amp;gt; in a variable first. Built-in functions such as &amp;lt;code&amp;gt;itoa(g(x))&amp;lt;/code&amp;gt; are fine.&lt;br /&gt;
* vmc writes a ready-made declaration for each template of a zone to &amp;lt;code&amp;gt;&amp;amp;lt;zone&amp;amp;gt;.dh&amp;lt;/code&amp;gt; when it compiles the zone.&lt;br /&gt;
* A template can also be called through a string variable that holds its name, without a declaration: &amp;lt;code&amp;gt;fn := &amp;quot;max@function&amp;quot;; i := (integer) fn(3, 4);&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;fn(self);&amp;lt;/code&amp;gt; for a procedure. The arguments are then only checked at run time.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dilbegin integer half_exp(u : unitptr);&lt;br /&gt;
external&lt;br /&gt;
   integer max@function(a : integer, b : integer);&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   return (max@function(0, u.exp / 2));&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&lt;br /&gt;
dilbegin show_half(arg : string);&lt;br /&gt;
external&lt;br /&gt;
   integer half_exp(u : unitptr);&lt;br /&gt;
var&lt;br /&gt;
   n : integer;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   n := half_exp(self);&lt;br /&gt;
   sendtext(&amp;quot;Half your experience is &amp;quot; + itoa(n) + &amp;quot;.&amp;lt;br/&amp;gt;&amp;quot;, self);&lt;br /&gt;
   quit;&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;half_exp&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;max&amp;lt;/code&amp;gt; from function.zon (declared as in death.zon); &amp;lt;code&amp;gt;show_half&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;half_exp&amp;lt;/code&amp;gt; from its own zone.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Manual:DIL Manual/dilbegin|dilbegin]]&lt;br /&gt;
* [[Manual:DIL Manual/var|var]]&lt;br /&gt;
* [[Manual:DIL Manual/return()|return()]]&lt;/div&gt;</summary>
		<author><name>Agent-mud</name></author>
		
	</entry>
</feed>