Table of Contents
Introduction
The Ch language environment can be used
for network computing.
You can download Ch programs located remotely
in a server with the Ch language environment
and then execute them in the client, your host computer.
Such a network-downloaded program is called an applet.
If you have installed the Ch language environment according
to its installation instructions, you can
run
this Ch applet located remotely in our server
with the Ch language environment.
The program will be downloaded through the Web
and executed on your computer.
Don't worry, this is a benign program and it will not
do any harm to your system. Seeing is believing; take a look at the
source code of this Ch
applet.
You will find out that it is just a simple C program.
Indeed, Ch is designed to be a superset of C.
When you click the above
highlighted word
"run",
if the applet is not executed to produce the following output
Hello, world!
Today is (date)
and instead downloaded as a text file
C1.chs,
you should
download the Ch language environment.
Unlike other language environments,
the Ch language environment is very simple to setup.
Check
Ch Installation and System Administration Guide
on how to
setup the server and client of the Ch language environment.
When comparing different language environments,
people often try to construct a simple 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!
In Ch, what you see is what you get.
A Ch applet is executed without compilation.
No security error-prone intermediate bytecode
will be generated.
Extensions to C for Writing Secure Applets
Many secure features have been built into the Ch language environment
to protect your system from hostile and accidental attack.
For example, the C pointer declaration is disabled for applets
obtained through the network for World-Wide Distributed Computing
under a
safe shell.
If you
run
an applet with pointer indirection,
the execution of the
network-downloaded
program
will fail. The following error message will be produced
ERROR: lvalue of pointer type is restricted in safe shell
For across-network computing, a 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.
Many people find that computational arrays in Ch are cool.
A 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
can also be
executed
across the network because declaration of pointers and the indirection operation of a pointer
is permitted.
Integration of CGI Scripts and Applets
To demonstrate the difference between the
Ch-applet based network computing
and
the Common Gateway Interface,
run
this CGI program written in Ch.
In
Common Gateway Interface,
when you click the highlighted
word "run", the Ch program is executed on the Web
server, not on your client computer.
But, in
Ch-applet based network computing,
when you click the highlighted
word "run", the program is executed on your local machine.
Take a look at the source code of this
CGI program
written in Ch
to see the difference.
This simple
example
shows how an applet is created in the
server and
executed
in a client machine.
Many interesting and exciting applications can be created
using
CGI and Ch applets.
The creation of a dynamic applet is easy.
In this Web Calculator example, the error message
produced by the CGI script is sent as an 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-chs
indicates that the output
is
the MIME type of a dynamic applet in safe Ch.
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 of 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.
The
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 product of 2 by transpose of matrix A.
The Web Plotter
can plot 2-dimensional and 3-dimensional graphs according
to your input function.
Collection of CGI/CCI Scripts and Applets Presented in this Page
Applets
- Hello, world!
- Hello, world! and date.
- Applet with string data type.
- Applet with computational array.
- C++-style applet with function pass by reference.
- Applet with function pass by value of pointer.
- Applet with lvalue of pointer type.
(failed).
CGI Scripts
- Hello, world!
NOTE:
If you cannot run the applets
described in this page,
please come back to try these demos again after you
have
downloaded
and installed the
Ch language environment, it will be much more fun.