Home
About
Policies
FAQ
Forums
Registration
Password Recovery

Func (MPI)

From Tapestries MUCK

Revision as of 00:51, 31 March 2007 by Ash-Fox (Talk | contribs)
Jump to: navigation, search

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