As a side-effect, this function sets the value returned by time(1) to the current time.
Calling add_constant without a value will remove that name from the list of constants. As with replacing, this will not affect already compiled programs.
array aggregate(mixed ... elems) { return elems; }
multiset aggregate(mixed ... elems) { return mkmultiset(elems); }
The only problem is that mkmultiset is implemented using aggregate_multiset...
If seconds is zero, no new alarm is scheduled.
In any event any previously set alarm is canceled.
({
file, | /* a string with the filename if known, else zero */ |
line, | /* an integer containing the line if known, else zero */ |
function, | /* The function pointer to the called function */ |
mixed|void ..., | /* The arguments the function was called with */ |
The current call frame will be last in the array, and the one above that the last but one and so on.
({
time_left, | /* an int */ |
caller, | /* the object that made the call out */ |
function, | /* the function to be called */ |
arg1, | /* the first argument, if any */ |
arg2, | /* the second argument, if any */ |
... | /* and so on... */ |
Except of course it is a lot shorter and faster. That is, it indices every index in the array data on the value of the argument index and returns an array with the results.map_array(data, lambda(mixed x,mixed y) { return x[y]; }, index)
> column( ({ ({1,2}), ({3,4}), ({5,6}) }), 1) Result: ({2, 4, 6})
Almost any value can be coded, mappings, floats, arrays, circular structures etc. At present, objects, programs and functions cannot be saved in this way. This is being worked on.
Note that this function is more restrictive than encode_value() with respect to the types of values it can encode. It will throw an error if it can't encode to a canonical form.
For instance, enumerate(4) gives ({0,1,2,3}).
Advanced use: the resulting array is caluculated like this:
array enumerate(int n,mixed step,mixed start,function operator) { array res=({}); for (int i=0; i<n; i++) { res+=({start}); start=operator(start,step); } return res; }
The default values is step=1, start=0, operator=add.
({ int mode [0] file mode, protection bits etc. etc. int size [1] file size for regular files, -2 for dirs, -3 for links, -4 for otherwise int atime [2] last access time int mtime [3] last modify time int ctime [4] last status time change int uid [5] The user who owns this file int gid [6] The group this file belongs to })If you give 1 as a second argument, file_stat does not follow links.
If there is no such file or directory, zero is returned.
|
Some operating systems have problems if this function is used together with threads.
search(indices(haystack), index) != -1
For strings, has_value is equivalent to:search(values(haystack), value) != -1
search(haystack, value) != -1
Some signals and their supposed purpose:
SIGHUP | Hang-up, sent to process when user logs out |
SIGINT | Interrupt, normally sent by ctrl-c |
SIGQUIT | Quit, sent by ctrl-\ |
SIGILL | Illegal instruction |
SIGTRAP | Trap, mostly used by debuggers |
SIGABRT | Aborts process, can be caught, used by Pike whenever something goes seriously wrong. |
SIGBUS | Bus error |
SIGFPE | Floating point error (such as division by zero) |
SIGKILL | Really kill a process, cannot be caught |
SIGUSR1 | Signal reserved for whatever you want to use it for. |
SIGSEGV | Segmentation fault, caused by accessing memory where you shouldn't. Should never happen to Pike. |
SIGUSR2 | Signal reserved for whatever you want to use it for. |
SIGALRM | Signal used for timer interrupts. |
SIGTERM | Termination signal |
SIGSTKFLT | Stack fault |
SIGCHLD | Child process died |
SIGCONT | Continue suspended |
SIGSTOP | Stop process |
SIGSTP | Suspend process |
SIGTTIN | tty input for background process |
SIGTTOU | tty output for background process |
SIGXCPU | Out of CPU |
SIGXFSZ | File size limit exceeded |
SIGPROF | Profile trap |
SIGWINCH | Window change signal |
Note that you have to use signame to translate the name of a signal to its number.
When a module is loaded the functions init_module_efuns and init_module_programs are called to initialize it. When Pike exits exit_module is called in all dynamically loaded modules. These functions _must_ be available in the module.
Please see the source and any examples available at ftp://www.idonex.se/pub/pike for more information on how to write modules for Pike in C.
([ "sec" : int(0..59) seconds over the minute "min" : int(0..59) minutes over the hour "hour" : int(0..59) what hour in the day "mday" : int(1..31) day of the month "mon" : int(0..11) what month "year" : int(0..) years since 1900 "wday" : int(0..6) day of week (0=Sunday) "yday" : int(0..365) day of year "isdst" : int(0..1) is daylight saving time "timezone" : int difference between local time and UTC ])
advanced use is a wide combination of types given as "arr" or "fun".
|
This function returns the value from the key-value pair that was removed from the mapping.
> man( 1,2,3 );
Result: 3
> min( 1,2,3 );
Result: 1
> mkmultiset( ({1,2,3}) );
Result: (< /* 3 elements */
1,
2,
3
>)
year | The number of years since 1900 |
mon | The month |
mday | The day of the month. |
hour | The number of hours past midnight |
min | The number of minutes after the hour |
sec | The number of seconds after the minute |
isdst | If this is 1, daylight savings time is assumed |
tm | The timezone (-12 <= tz <= 12) |
Or you can just send them all on one line as the second syntax suggests.
/* This example calls shutting_down() in all cloned objects */
object o;
for(o=next_object();o;o=next_object(o))
o->shutting_down();
map_array(index,lambda(mixed x,mixed y) { return y[x]; },data)
Except of course it is a lot shorter and faster. That is, it indices data on every index in the array index and returns an array with the results.
0: user time 1: system time 2: maxrss 3: idrss 4: isrss 5: minflt 6: minor page faults 7: major page faults 8: swaps 9: block input op. 10: block output op. 11: messages sent 12: messages received 13: signals received 14: voluntary context switches 15: involuntary context switches 16: sysc 17: ioch 18: rtime 19: ttime 20: tftime 21: dftime 22: kftime 23: ltime 24: slptime 25: wtime 26: stoptime 27: brksize 28: stksize
Don't ask me to explain these values, read your system manuals for more information. (Note that all values may not be present though)
When the haystack is a mapping, search tries to find the index connected to the data needle. That is, it tries to lookup the mapping backwards. If needle isn't present in the mapping, zero is returned, and zero_type() will return 1 for this zero.
The callback will receive the signal number as the only argument. See the document for the function 'kill' for a list of signals.
If no second argument is given, the signal handler for that signal is restored to the default handler.
If the second argument is zero, the signal will be completely ignored.
Sort can sort strings, integers and floats in ascending order. Arrays will be sorted first on the first element of each array.
Sort returns its first argument.
Modifiers:
0 | Zero pad numbers (implies right justification) |
! | Toggle truncation |
' ' (space) | pad positive integers with a space |
+ | pad positive integers with a plus sign |
- | left adjusted within field size (default is right) |
| | centered within field size |
= | column mode if strings are greater than field size |
/ | Rough line break (break at exactly field size instead of between words) |
# | table mode, print a list of '\n' separated word (top-to-bottom order) |
$ | Inverse table mode (left-to-right order) |
n | (where n is a number or *) a number specifies field size |
.n | set precision |
:n | set field size & precision |
;n | Set column width |
* | if n is a * then next argument is used for precision/field size |
'X' | Set a pad string. ' cannot be a part of the pad_string (yet) |
~ | Get pad string from argument list. |
< | Use same arg again |
^ | repeat this on every line produced |
@ | do this format for each entry in argument array |
> | Put the string at the bottom end of column instead of top |
_ | Set width to the length of data |
Operators:
%% | percent |
%b | signed binary int |
%d | signed decimal int |
%o | signed octal int |
%x | lowercase signed hexadecimal int |
%X | uppercase signed hexadecimal int |
%c | char (or short with %2c, %3c gives 3 bytes etc.) |
%f | float |
%g | heuristically chosen representation of float |
%G | like %g, but uses uppercase E for exponent |
%e | exponential notation float |
%E | like %e, but uses uppercase E for exponent |
%F | binary IEEE representation of float (%4F gives single precision, %8F gives double precision.) |
%s | string |
%O | any type (debug style) |
%n | nop |
%t | type of argument |
%<modifiers>{format%} | do a format for every index in an array. |
Pike v0.7 release 1 running Hilfe v2.0 (Incremental Pike Frontend) > int screen_width=70; Result: 70 > mixed sample; > write(sprintf("fish: %c\n", 65)); fish: A Result: 8 > write(sprintf("num: %d\n", 10)); num: 10 Result: 8 > write(sprintf("num: %+10d\n", 10)); num: +10 Result: 16 > write(sprintf("num: %010d\n", 5*2)); num: 0000000010 Result: 16 > write(sprintf("num: %|10d\n", 20/2)); num: 10 Result: 16 > write(sprintf("%|*s\n",screen_width,"THE NOT END")); THE NOT END Result: 71 > write(sprintf("%|=*s\n",screen_width, "fun with penguins\n")); fun with penguins Result: 71 > write(sprintf("%-=*O\n",screen_width,({ "fish", 9, "gumbies", 2 }))); ({ /* 4 elements */ "fish", 9, "gumbies", 2 }) Result: 426 > write(sprintf("%-=*s\n", screen_width, "This will wordwrap the specified string within the "+ "specified field size, this is useful say, if you let "+ "users specify their screen size, then the room "+ "descriptions will automagically word-wrap as appropriate.\n"+ "slosh-n's will of course force a new-line when needed.\n")); This will wordwrap the specified string within the specified field size, this is useful say, if you let users specify their screen size, then the room descriptions will automagically word-wrap as appropriate. slosh-n's will of course force a new-line when needed. Result: 355 > write(sprintf("%-=*s %-=*s\n", screen_width/2, "Two columns next to each other (any number of columns will "+ "of course work) independently word-wrapped, can be useful.", screen_width/2-1, "The - is to specify justification, this is in adherence "+ "to std sprintf which defaults to right-justification, "+ "this version also supports center and right justification.")); Two columns next to each other (any The - is to specify justification, number of columns will of course this is in adherence to std work) independently word-wrapped, sprintf which defaults to can be useful. right-justification, this version also supports center and right justification. Result: 426 > write(sprintf("%-$*s\n", screen_width, "Given a\nlist of\nslosh-n\nseparated\n'words',\nthis option\n"+ "creates a\ntable out\nof them\nthe number of\ncolumns\n"+ "be forced\nby specifying a\nprecision.\nThe most obvious\n"+ "use is for\nformatted\nls output.")); Given a list of slosh-n separated 'words', this option creates a table out of them the number of columns be forced by specifying a precision. The most obvious use is for formatted ls output. Result: 312 > sample = ({"bing","womble","wuff","gul"}); Result: ({ /* 4 elements */ "bing", "womble", "wuff", "gul" }) > write(sprintf("This will apply the format strings between the\n" "procent-braces to all elements in the array:\n" "%{gurksallad: %s\n%}", sample)); This will apply the format strings between the procent-braces to all elements in the array: gurksallad: bing gurksallad: womble gurksallad: wuff gurksallad: gul Result: 162 > write(sprintf("Of course all the simple printf options "+ "are supported:\n %s: %d %x %o %c\n", "65 as decimal, hex, octal and a char", 65, 65, 65, 65)); Of course all the simple printf options are supported: 65 as decimal, hex, octal and a char: 65 41 101 A Result: 106 > write(sprintf("%|*s\n",screen_width, "THE END")); THE END Result: 71 > quit Exiting.
Throws an error if characters not legal in an UTF16 stream are encountered. Valid characters are in the range 0x00000 - 0x10ffff, except for characters 0xfffe and 0xffff.
Characters in range 0x010000 - 0x10ffff are encoded using surrogates.
Throws an error if characters not valid in an UTF8 stream are encountered. Valid characters are in the range 0x00000000 - 0x7fffffff.
If extended is 1, characters in the range 0x80000000-0xfffffffff will also be accepted, and encoded using a non-standard UTF8 extension.
The second syntax does not call the system call time() as often, but is only updated in the backed. (when Pike code isn't running)
The third syntax can be used to measure time more preciely than one second. It return how many seconds has passed since t. The precision of this function varies from system to system.
If useconds is zero, no new alarm is scheduled.
In any event any previously set alarm is canceled.
Throws an error if the stream is not a legal UFT8 byte-stream.
Accepts and decodes the extension used by string_to_utf8(), if extended is 1.
> version();
Result: "Pike v0.7 release 1"
If the argument is not an int, zero will be returned.