For a simple first program, create a text file named
/* This is a comment */ // This is a single-line comment print("Hello, world!\n");
To run the program above, use:
This should give the output
in your terminal.
Now consider the program
string name := read_string("Name", 50); print("Hello, ", name, "!\n");
The first statement causes SMART to prompt the user to enter a string
with at most 50 characters (reading until whitespace),
and store the result in a constant
Technically, there are no variables in SMART;
instead, we have defined a function with no parameters called
Hello, Enter the (string, length 50) value for Name : Alan Turing Alan!
This is because SMART is very lazy, and does not compute a value for
name until needed (in this case, when we try to print
after printing the string “Hello, “.).
A better version of this program would be:
string name := read_string("Name", 50); compute(name); print("Hello, ", name, "!\n");
compute(name) forces SMART to compute the value for
If we run this program, we should obtain:
Enter the (string, length 50) value for Name : Alan Turing Hello, Alan!