1
[subsection {A Simple Procedure}]
3
Starting simple, let us assume that the Tcl code in question is
8
return [expr {(sin($x)*rand())/$y**log($z)}]
12
with the expression pretending to be something very complex and
13
slow. Converting this to C we get:
16
package require critcl
18
critcl::cproc math {double x double y double z} double {
19
double up = rand () * sin (x);
20
double down = pow(y, log (z);
25
Notable about this translation:
27
[list_begin enumerated]
28
[enum] All the arguments got type information added to them, here
29
"double". Like in C the type precedes the argument name. Other
30
than that it is pretty much a Tcl dictionary, with keys and
32
[enum] We now also have to declare the type of the result, here
34
[enum] The reference manpage lists all the legal C types supported as
35
arguments and results.