pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.480 2003/03/28 14:23:28 marcus Exp $ + || $Id: builtin_functions.c,v 1.481 2003/04/01 18:09:40 nilsson Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.480 2003/03/28 14:23:28 marcus Exp $"); + RCSID("$Id: builtin_functions.c,v 1.481 2003/04/01 18:09:40 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"   #include "constants.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/builtin_functions.c:61:   #endif      /* #define DIFF_DEBUG */   /* #define ENABLE_DYN_DIFF */      /*! @decl int equal(mixed a, mixed b)    *!    *! This function checks if the values @[a] and @[b] are equal.    *!    *! For all types but arrays, multisets and mappings, this operation is -  *! the same as doing @code{@[a] == @[b]@}. +  *! the same as doing @expr{@[a] == @[b]@}.    *! For arrays, mappings and multisets however, their contents are checked    *! recursively, and if all their contents are the same and in the same    *! place, they are considered equal.    *!    *! @seealso    *! @[copy_value()]    */   PMOD_EXPORT void f_equal(INT32 args)   {    int i;
pike.git/src/builtin_functions.c:85:    i=is_equal(Pike_sp-2,Pike_sp-1);    pop_n_elems(args);    push_int(i);   }      /*! @decl array aggregate(mixed ... elements)    *!    *! Construct an array with the arguments as indices.    *!    *! This function could be written in Pike as: -  *! @code{array aggregate(mixed ... elems) { return elems; }@} +  *! @code +  *! array aggregate(mixed ... elems) { return elems; } +  *! @endcode    *!    *! @note    *! Arrays are dynamically allocated there is no need to declare them -  *! like @code{int a[10]=allocate(10);@} (and it isn't possible either) like -  *! in C, just @code{array(int) a=allocate(10);@} will do. +  *! like @expr{int a[10]=allocate(10);@} (and it isn't possible either) like +  *! in C, just @expr{array(int) a=allocate(10);@} will do.    *!    *! @seealso    *! @[sizeof()], @[arrayp()], @[allocate()]    */   PMOD_EXPORT void debug_f_aggregate(INT32 args)   {    struct array *a;   #ifdef PIKE_DEBUG    if(args < 0) Pike_fatal("Negative args to f_aggregate() (%d)\n",args);   #endif
pike.git/src/builtin_functions.c:887:    *! @decl int has_index(mapping haystack, mixed index)    *!    *! Search for @[index] in @[haystack].    *!    *! @returns    *! Returns @tt{1@} if @[index] is in the index domain of @[haystack],    *! or @tt{0@} (zero) if not found.    *!    *! This function is equivalent to (but sometimes faster than):    *! -  *! @code{search(indices(haystack), index) != -1@} +  *! @code +  *! search(indices(haystack), index) != -1 +  *! @endcode    *!    *! @note    *! A negative index in strings and arrays as recognized by the    *! index operators @tt{`[]()@} and @tt{`[]=()@} is not considered    *! a proper index by @[has_index()]    *!    *! @seealso    *! @[has_value()], @[indices()], @[search()], @[values()], @[zero_type()]    */   PMOD_EXPORT void f_has_index(INT32 args)
pike.git/src/builtin_functions.c:976:    *!    *! Search for @[value] in @[haystack].    *!    *! @returns    *! Returns @tt{1@} if @[value] is in the value domain of @[haystack],    *! or @tt{0@} (zero) if not found.    *!    *! This function is in all cases except when both arguments are strings    *! equivalent to (but sometimes faster than):    *! -  *! @code{search(values(@[haystack]), @[value]) != -1@} +  *! @code +  *! search(values(@[haystack]), @[value]) != -1 +  *! @endcode    *!    *! If both arguments are strings, @[has_value()] is equivalent to:    *! -  *! @code{search(@[haystack], @[value]) != -1@} +  *! @code +  *! search(@[haystack], @[value]) != -1 +  *! @endcode    *!    *! @seealso    *! @[has_index()], @[indices()], @[search()], @[values()], @[zero_type()]    */   PMOD_EXPORT void f_has_value(INT32 args)   {    if(args < 2)    SIMPLE_TOO_FEW_ARGS_ERROR("has_value", 2);    if(args > 2)    pop_n_elems(args-2);
pike.git/src/builtin_functions.c:2962:    *! different syntaxes do different things as follows:    *!    *! If all the arguments are strings, a copy of @[s] with every    *! occurrence of @[from] replaced with @[to] will be returned.    *! Special case: @[to] will be inserted between every character in    *! @[s] if @[from] is the empty string.    *!    *! If the first argument is a string, and the others array(string), a string    *! with every occurrance of @[from][@i{i@}] in @[s] replaced with    *! @[to][@i{i@}] will be returned. Instead of the arrays @[from] and @[to] -  *! a mapping equvivalent to @code{@[mkmapping](@[from], @[to])@} can be +  *! a mapping equvivalent to @expr{@[mkmapping](@[from], @[to])@} can be    *! used.    *!    *! If the first argument is an array or mapping, the values of @[a] which    *! are @[`==()] with @[from] will be replaced with @[to] destructively.    *! @[a] will then be returned.    *!    *! @note    *! Note that @[replace()] on arrays and mappings is a destructive operation.    */   PMOD_EXPORT void f_replace(INT32 args)
pike.git/src/builtin_functions.c:3784:    sort_array_destructively(Pike_sp[-args].u.array);    }   }      /*! @decl array rows(mixed data, array index)    *!    *! Select a set of rows from an array.    *!    *! This function is en optimized equivalent to:    *! -  *! @code{map(@[index], lambda(mixed x) { return @[data][x]; })@} +  *! @code +  *! map(@[index], lambda(mixed x) { return @[data][x]; }) +  *! @endcode    *!    *! That is, it indices data on every index in the array index and    *! returns an array with the results.    *!    *! @seealso    *! @[column()]    */   PMOD_EXPORT void f_rows(INT32 args)   {    INT32 e;
pike.git/src/builtin_functions.c:5467:       push_array(ad);    push_array(bd);    return aggregate_array(2);   }      /*! @decl array permute(array in, int number)    *!    *! Give a specified permutation of an array.    *! -  *! The number of permutations is equal to @code{sizeof(@[in])!@} +  *! The number of permutations is equal to @expr{sizeof(@[in])!@}    *! (the factorial of the size of the given array).    *!    *! @seealso    *! @[shuffle()]    */   PMOD_EXPORT void f_permute( INT32 args )   {    INT_TYPE q, i=0, n;    struct array *a;    struct svalue *it;
pike.git/src/builtin_functions.c:6649:    *!    *! @item mapping    *! @[fun] is applied to the values, and each result is assigned    *! to the same index in a new mapping, which is returned.    *!    *! @item program    *! The program is treated as a mapping containing the    *! identifiers that are indexable from it and their values.    *!    *! @item object -  *! If there is a @code{cast@} method in the object, it's called +  *! If there is a @[lfun::cast] method in the object, it's +  *! called    *! to try to cast the object to an array, a mapping, or a    *! multiset, in that order, which is then handled as described    *! above.    *! @enddl    *!    *! @[fun] is applied in different ways depending on its type:    *!    *! @dl    *! @item function    *! @[fun] is called for each element. It gets the current    *! element as the first argument and @[extra] as the rest. The    *! result of the call is collected.    *!    *! @item object    *! @[fun] is used as a function like above, i.e. the -  *! @code{`()@} method in it is called. +  *! @[lfun::`()] method in it is called.    *!    *! @item multiset    *! @item mapping    *! @[fun] is indexed with each element. The result of that is    *! collected.    *!    *! @item "zero or left out"    *! Each element that is callable is called with @[extra] as    *! arguments. The result of the calls are collected. Elements    *! that aren't callable gets zero as result.
pike.git/src/builtin_functions.c:7030:    *!    *! @item mapping    *! The values are filtered with @[fun], and the index/value    *! pairs it accepts are kept in the returned mapping.    *!    *! @item program    *! The program is treated as a mapping containing the    *! identifiers that are indexable from it and their values.    *!    *! @item object -  *! If there is a @code{cast@} method in the object, it's called +  *! If there is a @[lfun::cast] method in the object, it's called    *! to try to cast the object to an array, a mapping, or a    *! multiset, in that order, which is then filtered as described    *! above.    *! @enddl    *!    *! Unless something else is mentioned above, @[fun] is used as    *! filter like this:    *!    *! @dl    *! @item function    *! @[fun] is called for each element. It gets the current    *! element as the first argument and @[extra] as the rest. The    *! element is kept if it returns true, otherwise it's filtered    *! out.    *!    *! @item object    *! The object is used as a function like above, i.e. the -  *! @code{`()@} method in it is called. +  *! @[lfun::`()] method in it is called.    *!    *! @item multiset    *! @item mapping    *! @[fun] is indexed with each element. The element is kept if    *! the result is nonzero, otherwise it's filtered out.    *!    *! @item "zero or left out"    *! Each element that is callable is called with @[extra] as    *! arguments. The element is kept if the result of the call is    *! nonzero, otherwise it's filtered out. Elements that aren't
pike.git/src/builtin_functions.c:7314:    *! @decl array enumerate(int n, void|mixed step, void|mixed start, @    *! void|function operator)    *!    *! Create an array with an enumeration, useful for initializing arrays    *! or as first argument to @[map()] or @[foreach()].    *!    *! The defaults are: @[step] = 1, @[start] = 0, @[operator] = @[`+]    *!    *! @section Advanced use    *! The resulting array is calculated like this: -  *! @code{ -  *! array enumerate(int n, mixed step, mixed start, function operator) -  *! { -  *! array res = allocate(n); -  *! for (int i=0; i < n; i++) -  *! { -  *! res[i] = start; -  *! start = operator(start, step); -  *! } -  *! return res; -  *! } -  *! @} +  *! @code +  *! array enumerate(int n, mixed step, mixed start, function operator) +  *! { +  *! array res = allocate(n); +  *! for (int i=0; i < n; i++) +  *! { +  *! res[i] = start; +  *! start = operator(start, step); +  *! } +  *! return res; +  *! } +  *! @endcode    *! @endsection    *!    *! @seealso    *! @[map()], @[foreach()]    */   void f_enumerate(INT32 args)   {    struct array *d;    int i;    INT_TYPE n;