)
( ( (
) ) )
------
oooooo
||
||
Hello, world!
Today is (date)
and instead downloaded as a text file
C1.sch,
you should
download the CH language environment.
Unlike other language evnrionments,
the CH language environment is very simple to setup.
Check my
Technical Support Notes
on how to
setup the client of the CH language environment
for World-Wide Distributed Computing.
If there is a system administrator in your organization,
you may ask him to install
the CH language environment for you. It shall take
him less than 10 minuets to install it.
If you are a Linuxer, install it by yourself.
When comparing different language environments, people often try to construct a simplest program to print out "Hello, world!" Here is a CH applet for such a beauty contest. It can be executed to print out this famous statement.
Hello, world!
For your information, you may want to take
a look at the equivalent
hello-world applet written in Java
by members of the Java development team.
In CH, what you see is what you get.
A CH applet is executed without compilation.
In Java, that 9 lines hello-world Java program
with object-oriented classes (not for average Joe to write and read)
has to be compiled as a bytecode (like a machine code not
for human being to read) before it can be
treated as an applet for sophisticated
integration with html files.
Some
differences
between CH and Java
from the internet computing point of view are highlighted.
ERROR: pointer * is restricted in safe shell
For across-network computing, string is treated as a first-class
object. You can
run
this
applet
with string data type to produce the following output
Hello, world!
I have just run the CH language environment.
It is cool!
However, an applet can invoke
other programs with C pointers located in a client computer.
which will be described in the next section.
Fortran programmers without knowing C pointers will find that writing CH applets for World-Wide Distributed Computing is easy. This Fortran-style CH applet can be downloaded and executed on your local machine to produce the following output
complex(26.117,-7.972)
Many people find computational arrays in CH are cool.
Computational array is a first-class object in CH.
Here is a CH
program
with computational arrays, the output
A =
1.000 2.000 3.000
4.000 5.000 6.000
7.000 8.000 9.000
B =
1.000 2.000 3.000
transpose(A) =
1.000 4.000 7.000
2.000 5.000 8.000
3.000 6.000 9.000
A*B =
14.000 32.000 50.000
transpose(A)+2*inverse(A)*A =
3.000 4.000 7.000
2.000 22.000 8.000
3.000 6.000 11.000
will be produced by
executing it.
All nice features in Fortran 90 will be available in
the CH language environment.
How can you pass results from a function without pointers in
applets?
Fortran programmers will say pass-by-reference.
Yes! you can pass arguments of function by reference in CH.
References in CH are C++ compatible.
Try to
run
this
C++ style applet
with reference data type.
The following output will be produced
x=4,y=5
x=5,y=4
The equivalent
C version
of the above C++ style applet
cannot be
executed
across the network because of declaration of pointers.
Many interesting and exciting applications can be created using CGI and WWDC features in the CH language environment. Here is my Web Calculator. In this example, your input is processed by this CH CGI script with less than 50 lines of C code executed in the CH language envrionment. The CGI program dynamically creates a CH applet in the fly. This applet is then executed in your machine. Such an applet that is created and delivered on demand is called dynamic applet. The creation of dynamic applet is easy. In this Web Calculator example, the error message produced by the CGI script is sent as a html file, which is realized by producing the first line of output
content-type: text/html
followed by a blank line.
The first line of output from the CGI script
content-type: application/x-ch
indicates that the output
is
the MIME type of CH dynamic applet.
For example, when you input x with value 3 and
expression of x*sin(2*x) into this
Web Calculator, the following dynamic applet will be created
by the CH CGI script and then executed in your local machine.
#include<stdio.h>
int main() {
double x = 3;
printf("x = %f, ", x);
printf("x*sin(2*x) = %f\n", x*sin(2*x));
}
The output from the above program is
x = 3.000000, x*sin(2*x) = -0.838246
A program with similar functionalities may be
implemented in C and X-Window alone
with thousands lines of code.
That is why CH is a very high-level language environment.
Many applications can be accomplished in
the CH language environment with a fraction of C code.
This
Web Matrix Calculator
will demonstrate the power of computational arrays in the
CH language environment.
For example, if you type in
mathematical expression
inverse(A)+2*tranpose(A),
the Matrix Calculator will compute
the sum of inverse of matrix A
and produt of 2 by transpose of matrix A.
Here is the
CGI script
that generates dynamic applet for this Web Matrix Calculator.
As another example, this Web Plotter can plot 2-dimensional and 3-dimensional graphs according to your input function. By default, the following dynamic applet will be executed in the fly in your local machine for a 3-dimensional graph. This picture will appear on your screen.
#include<stdio.h>
int main() {
float data[1600][3], StepX, StepY, MinX, MaxX, MinY, MaxY, x, y, z;
int pointsX, pointsY, i, j, k=0;
MinX = 0.000000;
MaxX = 6.283000;
MinY = 0.000000;
MaxY = 6.283000;
pointsX = 40;
pointsY = 40;
StepX = (MaxX - MinX)/(pointsX-1);
StepY = (MaxY - MinY)/(pointsY-1);
for(i=0;i<pointsX;i++) {
for(j=0;j<pointsY;j++,k++) {
x = MinX + (i*StepX);
y = MinY + (j*StepY);
z = cos(x)*cos(y);
data[k][0] = x;
data[k][1] = y;
data[k][2] = z;
}
}
plotxyz(data, "Plot of z = cos(x)*cos(y)", "X", "Y", "Z");
}
After you have started Mosaic(V2.5 or higher) in your local machine and set the port number that CCI is listening for, then click
int main() {
string slide[4] = {
"http://iel.ucdavis.edu/",
"http://iel.ucdavis.edu/CH/",
"http://iel.ucdavis.edu/CH/tutor/wwdc/wwdc.html",
NULL
};
string host_name = "local.host.ucdavis.edu";
int port_num = 8822;
int show_time = 1;
slides(slide, host_name, port_num, show_time);
}
Function slides() is a
function file
distributed
along with the CH language environment.
You can find this function by typing
which slides
in the CH shell.