Home
About
Policies
FAQ
Forums
Registration
Password Recovery

Func (MPI)

From Tapestries MUCK

(Difference between revisions)
Jump to: navigation, search
(Corrected link(s) with new MPI naming scheme.)
 
Line 2: Line 2:
=func=
=func=
<mpi>{func:name,vars...,def}</mpi>
<mpi>{func:name,vars...,def}</mpi>
-
This effectively defines a function in MPI, with the given name, that takes the given named variables.
+
This effectively defines a function in [[MPI]], with the given name, that takes the given named variables.
The function is not immediately evaluated, so it needs to be invoked later, to do anything.  Here's an example:
The function is not immediately evaluated, so it needs to be invoked later, to do anything.  Here's an example:
Line 11: Line 11:
<mpi>{sqr:10}</mpi>
<mpi>{sqr:10}</mpi>
-
Effectively, the above {[[MPI func|func]]} declaration is the same as the following macro, and in fact, it's internally handled the same way:
+
Effectively, the above {[[Func (MPI)|func]]} declaration is the same as the following macro, and in fact, it's internally handled the same way:
<mpi>_msgmacs/sqr:{with:val,{:1},{mult:{&val},{&val}}}</mpi>
<mpi>_msgmacs/sqr:{with:val,{:1},{mult:{&val},{&val}}}</mpi>

Latest revision as of 04:44, 31 March 2007

func

{func:name,vars...,def}

This effectively defines a function in MPI, with the given name, that takes the given named variables.

The function is not immediately evaluated, so it needs to be invoked later, to do anything. Here's an example:

{func:sqr,val,{mult:{&val},{&val}}}

This defines the function 'sqr', that takes a single argument. That argument is stored in the 'val' variable. The function will multiply the value of the number passed to it, by itself, returning the result. It's invoked like:

{sqr:10}

Effectively, the above {func} declaration is the same as the following macro, and in fact, it's internally handled the same way:

_msgmacs/sqr:{with:val,{:1},{mult:{&val},{&val}}}

You can define a function that takes more than one argument, but the maximum number of args you can pass to the function is seven. Example of multiple arguments:

     {func:names,list,numsp,flagsp,
 	{parse:v,{&list},
 	    {name:{&v}}
 	    {if:{or:{&numsp},{&flagsp}},
 		{lit:(}
 		{if:{&numsp},{ref:{&v}}}
 		{if:{&flagsp},{flags:{&v}}}
 		{lit:)}
 	    }
 	}
     }
     {names:{contents:here},1,1}
 
Personal tools
Namespaces
Variants
Actions
navagation
information
wiki
Toolbox