cool programming– working with output string

To print hello world in your cool programming, you should write this program

class Main{
i:IO<-new IO; main():Int{{i.out_string("Hello world!\n");1;}}; };[/code] here, i is an Input and output object. out-string print the hello world string. 1 is the return type which is written at the main function. main function will starting of the program as other programming languages like c,java. [code]main():Int{};[/code] the code says main function will return integer type value. If we write this below code [code]main():Int{1};[/code] it will return 1. Moreover the function main body is in a block which is [code] main():Int{{i.out_string("Hello world!\n");1;}}; [/code] for that the code has curly braces at the begin and end. If we store this file in hello.cl, we should compile the program using [code] coolc hello.cl [/code] it will produce assembly file called hello.s and we can run this by using [code] spim hello.s [/code] The output will be hello world. We could do the program other ways, [code] class Main{ i:IO<-new IO; main():IO {i.out_string("Hello world!\n")}; }; [/code] Here the main function will return IO that means input output. Another, example could be [code] class Main{ i:IO<-new IO; main():Object {i.out_string("Hello world!\n")}; }; [/code] Here the main function return object. Which is also be a output string. Moreover we can write like below. We could do the initialization of IO in the output string. It will also work. [code] class Main{ main():Object { (new IO).out_string("Hello world!\n")}; }; [/code] We could inherits IO class like OOP programming. [code] class Main inherits IO{ main():Object { self.out_string("Hello world!\n")}; }; [/code] self indicates the object. [code] class Main inherits IO{ main():Object { out_string("Hello world!\n")}; }; [/code] if you want to comment in the cool programming you should include parenthesis and star like this. [code](* this is test comment *)[/code]