File: special_functions.xml

package info (click to toggle)
pike7.8 7.8.866-7
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 69,304 kB
  • ctags: 28,082
  • sloc: ansic: 252,877; xml: 36,537; makefile: 4,214; sh: 2,879; lisp: 655; asm: 591; objc: 212; pascal: 157; sed: 34
file content (79 lines) | stat: -rw-r--r-- 2,253 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<chapter title="Special Functions">

<p>There are some 'functions' in Pike that are not really functions at all but
builtin items that can do things that no other functions can do. Some of them
can not be re-defined or overloaded.
In this chapter I will describe these functions and why they are implemented
as special functions.</p>

<section title="sscanf">

<p>Sscanf may look exactly like a normal function, but normal functions
can not set the variables you send to it. The purpose of sscanf is to
match one string against a format string and place the matching results
into a list of variables. See <ref>sscanf</ref> for full documentation.</p>

</section>


<section title="catch">

<p>Catch is used to trap errors and other exceptions in Pike.
It works by making a block of code into an expression, like this:</p>

<example>
catch { statements }
</example>

<p>If an error occurs, catch will return a description of the error.
The description of the error has the following format:</p>

<example>
({
   "error description",
   backtrace()
})
</example>

<p>If no error occurs, catch will return zero. You may emulate your own errors
using the function throw or error.</p>

<example>
int x,y;
// This might generate "division by zero"
array error = catch { x/=y; };
</example>

</section>

<section title="gauge">

<p>The syntax for gauge is the same as the syntax for catch:</p>

<example>
gauge { statements }
</example>

<p>However, gauge simply returns how many seconds the code took to execute.
This can be used to find out how fast your code actually is.. :)
Only CPU time used by the Pike process is measured. This means that if it takes
two seconds to execute but only uses 50 % CPU, this function will return 1.0.</p>

</section>

<section title="typeof">

<p>This function returns the type of an expression as a string. It does not
evaluate the expression at all, which might be somewhat confusing.</p>

<example>
typeof( exit(1) )
</example>

<p>This will return the string <tt>"void"</tt> since exit is a function that
returns void. It will not execute the function <tt>exit</tt> and exit the process as you
might expect. If you want to know the type after evaluation, use
<expr>sprintf("%t", expr)</expr>.</p>
</section>

</chapter>