~ubuntu-branches/ubuntu/utopic/critcl/utopic

« back to all changes in this revision

Viewing changes to doc/include/using_eproc.inc

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura
  • Date: 2013-05-11 00:08:06 UTC
  • Revision ID: package-import@ubuntu.com-20130511000806-7hq1zc3fnn0gat79
Tags: upstream-3.1.9
ImportĀ upstreamĀ versionĀ 3.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
[subsection {A Simple Procedure}]
 
2
 
 
3
Starting simple, let us assume that the Tcl code in question is
 
4
something like
 
5
 
 
6
[example {
 
7
    proc math {x y z} {
 
8
        return [expr {(sin($x)*rand())/$y**log($z)}]
 
9
    }
 
10
}]
 
11
 
 
12
with the expression pretending to be something very complex and
 
13
slow. Converting this to C we get:
 
14
 
 
15
[example {
 
16
    package require critcl
 
17
 
 
18
    critcl::cproc math {double x double y double z} double {
 
19
        double up   = rand () * sin (x);
 
20
        double down = pow(y, log (z);
 
21
        return up/down;
 
22
    }
 
23
}]
 
24
 
 
25
Notable about this translation:
 
26
 
 
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
 
31
       values swapped.
 
32
[enum] We now also have to declare the type of the result, here
 
33
       "double", again.
 
34
[enum] The reference manpage lists all the legal C types supported as
 
35
       arguments and results.
 
36
[list_end]