The file graph1.scm contains two Scheme functions that you should translate to each of the other languages.
Scheme | (begin S1 S2 ... Sn ) |
Pascal | begin   S1; S2; ... ; Sn   end |
C++, Java | { S1; S2; ... ; Sn; } |
Note that in Pascal there is not a ; after the last statement Sn in a begin group, although some Pascal compilers may accept one. Call st->lang to print the sub-statements Si; add 3 to indent for the sub-statements to make the code more readable.
Scheme | (if expr S1 S2 ) | (if expr S1 ) |
Pascal | if expr   then   S1   else   S2 | if expr   then   S1 |
C++, Java | if ( expr )   S1   else   S2 | if ( expr )   S1 |
Scheme | (dotimes ( i   n ) code ) |
Pascal | for i := 0 to n - 1 do   code |
C++, Java | for ( i = 0; i < n; i++)   code |
Note that in the target languages, code must be a single statement; this can be accomplished by consing a begin onto the list of code.
Scheme | (while   test   code ) |
Pascal | while test   do   code |
C++, Java | while ( test )   code |
Note that in the target languages, code must be a single statement; this can be accomplished by consing a begin onto the list of code.
Pascal | var i:integer; x:real; |
C++ | int i; float x; |
Java | long i; double x; |
Append these assignment statements and the code of the let and cons a begin onto the front. Then print the begin statement using st->lang.
First, print the procedure or function header. For the two test cases, these should be:
Pascal | procedure graph1; |
C++ | void graph1() { |
Java | public static void graph1() { |
Pascal | function factorial(n:integer):integer; |
C++ | int factorial(int n) { |
Java | public static long factorial(long n) { |
For Pascal, the result type of the function follows the arguments; for C++ and Java, the result type precedes the function name.
Next, call st->lang to print the code with an indentation of 3. If the code is not a let, let*, or begin, cons a begin onto the list of code to force it to be a begin.
Finally, print closing punctuation and the name of the procedure or function as a comment:
Pascal | ; {graph1} |
C++, Java | } // graph1 |
You may use any version of Java you wish. The class web page has instructions for downloading Java SDK (32 MB) and BlueJ.
To run your programs using BlueJ: