Introduction to Programming in ATS: | ||
---|---|---|
<<< Previous | Next >>> |
It is most likely that you want to write programs in the programming language you are learning. You may also want to try some of the examples included in this book and see what really happens. So I will first show you how to write in ATS a single-file program, that is, a program contained in a single file, and compile it and then execute it.
The following example is a program in ATS that prints out (onto the console) the string "Hello, world!" and a newline before it terminates:
The keyword val initiates a binding between the variable _void_ and the function call print ("Hello, world!\n"). However, this binding is never used after it is introduced; its sole purpose is for the call to the print function to get evaluated.The function main is of certain special meaning in ATS, which I will explain elsewhere. For a programmer who knows the C or Java programming language, I simply point out that the role of main is essentially the same as its counterpart of the same name in C or Java. The keyword implement initiates the implementation of a function whose interface has already been declared elsewhere. The declared interface for main in ATS is given as follows:
which indicates that main is a nullary function, that is, a function that takes no arguments, and it returns no value (or it returns the void value). The double slash symbol (//) initiates a comment that terminates at the end of the current line.Suppose that you have already installed the ATS programming language system. You can issue the following command-line to generate an executable named hello in the current working directory:
where hello.dats is a file containing the above program. Note that the filename extension .dats should not be altered as it has already been assigned a special meaning that the compilation command atscc recognizes. Another special filename extension is .sats, which we will encounter elsewhere.<<< Previous | Home | Next >>> |
Basic Functional Programming | Up | A Template for Single-File Programs |