Previous section To contents Next section

14.12 Simulate

This module is used to achieve better compatibility with older versions of Pike. It can also be used for convenience, but I would advice against it since some functions defined here are much slower than using similar functions in other modules. The purpose of this section in the manual is to make it easier for the reader to understand code that uses the Simulate module, not to encourage the use of the Simulate module.

Simulate inherits the Array, Stdio, String and Process modules, so importing he Simulate module also imports all identifiers from these modules. In addition, these functions are available:

FUNCTION
Simulate.member_array - find first occurrence of a value in an array

SYNTAX
int member_array(mixed item, array arr);

DESCRIPTION
Returns the index of the first occurrence of item in array arr. If not found, then -1 is returned. This is the same as search(arr, item).

FUNCTION
Simulate.previous_object - return the calling object

SYNTAX
object previous_object();

DESCRIPTION
Returns an object pointer to the object that called current function, if any.

SEE ALSO
backtrace

FUNCTION
Simulate.this_function - return a function pointer to the current function

SYNTAX
function this_function();

DESCRIPTION
Returns a function pointer to the current function, useful for making recursive lambda-functions.

SEE ALSO
backtrace

FUNCTION
Simulate.get_function - fetch a function from an object

SYNTAX
function get_function(object o, string name);

DESCRIPTION
Defined as: return o[name];

FUNCTION
Simulate.map_regexp - filter an array through a regexp

SYNTAX
array(string) map_regexp(array(string) arr, string reg);

DESCRIPTION
Returns those strings in arr that matches the regexp in reg.

SEE ALSO
Regexp

CONSTANT
Simulate.PI - pi

SYNTAX
PI;

DESCRIPTION
This is not a function, it is a constant roughly equal to the mathematical constant Pi.

FUNCTION
Simulate.all_efuns - return all 'efuns'

SYNTAX
mapping all_efuns();

DESCRIPTION
This function is the same as all_constants.

SEE ALSO
all_constants

FUNCTION
Simulate.explode - explode a string on a delimeter

SYNTAX
string explode(string s, string delimiter);

DESCRIPTION
This function is really the same as the division operator. It simly divides the string s into an array by splitting s at every occurance of delimeter.

SEE ALSO
Simulate.implode

FUNCTION
Simulate.filter_array - filter an array through a function

SYNTAX
array filter_array(array arr,function fun,mixed ... args);
array filter_array(array(object) arr,string fun,mixed ... args);
array filter_array(array(function) arr,-1,mixed ... args);

DESCRIPTION
Filter array is the same function as Array.filter.

SEE ALSO
Array.filter

FUNCTION
Simulate.implode - implode an array of strings

SYNTAX
string implode(array(string) a, string delimiter);

DESCRIPTION
This function is the inverse of explode. It concatenates all the strings in a with a delimiter in between each.

This function is the same as multiplication.

EXAMPLE
> implode( ({ "foo","bar","gazonk"}), "-" );
Result: foo-bar-gazonk
> ({ "a","b","c" })*" and ";
Result: a and b and c
>

SEE ALSO
Simulate.explode

FUNCTION
Simulate.m_indices - return all indices from a mapping

SYNTAX
array m_indices(mapping m);

DESCRIPTION
This function is equal to indices.

SEE ALSO
indices

FUNCTION
Simulate.m_sizeof - return the size of a mapping

SYNTAX
int m_sizeof(mapping m);

DESCRIPTION
This function is equal to sizeof.

SEE ALSO
sizeof

FUNCTION
Simulate.m_values - return all values from a mapping

SYNTAX
array m_values(mapping m);

DESCRIPTION
This function is equal to values.

SEE ALSO
values

FUNCTION
Simulate.map_array - map an array over a function

SYNTAX
array map_array(array arr,function fun,mixed ... args);
array map_array(array(object) arr,string fun,mixed ... args);
array map_array(array(function) arr,-1,mixed ... arg);

DESCRIPTION
This function is the same as Array.map.

SEE ALSO
Array.map

FUNCTION
Simulate.strstr - find a string inside a string

SYNTAX
int strstr(string str1,string str2);

DESCRIPTION
Returns the position of str2 in str1, if str2 can't be found in str1 -1 is returned.

SEE ALSO
sscanf, Simulate.explode and search

FUNCTION
Simulate.sum - add values together

SYNTAX
int sum(int ... i);
float sum(float ... f);
string sum(string|float|int ... p);
array sum(array ... a);
mapping sum(mapping ... m);
list sum(multiset ... l);

DESCRIPTION
This function does exactly the same thing as adding all the arguments together with +. It's just here so you can get a function pointer to the summation operator.

FUNCTION
Simulate.add_efun - add an efun or constant

SYNTAX
void add_efun(string func_name, mixed function)
void add_efun(string func_name)

DESCRIPTION
This function is the same as add_constant.

SEE ALSO
Simulate.add_constant

FUNCTION
Simulate.l_sizeof - return the size of a multiset

SYNTAX
int l_sizeof(multiset m);

DESCRIPTION
This function is equal to sizeof.

SEE ALSO
sizeof

FUNCTION
Simulate.listp - is the argument a list? (multiset)

SYNTAX
int listp(mixed l);

DESCRIPTION
This function is the same as multisetp.

SEE ALSO
Simulate.multisetp

FUNCTION
Simulate.mklist - make a multiset

SYNTAX
multiset mklist(array a);

DESCRIPTION
This function creates a multiset from an array.

EXAMPLE
> mklist( ({1,2,3}) ); Result: (< /* 3 elements */ 1, 2, 3 >)

SEE ALSO
aggregate_multiset

FUNCTION
Simulate.aggregate_list - aggregate a multiset

SYNTAX
multiset aggregate_list(mixed ... args);

DESCRIPTION
This function is exactly the same as aggregate_multiset.

SEE ALSO
aggregate_multiset

FUNCTION
Simulate.query_host_name - return the name of the host we are running on

SYNTAX
string query_host_name();

DESCRIPTION
This function returns the name of the machine the interpreter is running on. This is the same thing that the command 'hostname' prints.


Previous section To contents Next section