![](https://csdnimg.cn/release/download_crawler_static/86529930/bg1.jpg)
This is the traditional “hello world” program.
1
import "io"
let start() be
out("Greetings, Human.")
• import is a lot like import in java, and a bit like #include in C++.
• “io” is the standard library with input/output and other very basic functions.
• let introduces most simple declarations, it is not a type. There are no types.
• start serves the same purpose as main in java and C++.
• be is required when defining a function like this.
• The body of a function is a single statement, but see the next example.
• out is the ancestor of C’s printf and java’s System.out.printf.
Here is a bigger version.
import "io"
let start() be
{ out("Greetings, Human.");
out("Now go away and leave me alone.") }
• Curly brackets combine multiple statements into one statement, called a block.
• Semicolons are only required between statements, as a separator.
(the original BCPL didn’t require semicolons at all, but that leads to too
many preventable mistakes, so I made a change there)
• But if you forget and put an extra one before the }, the compiler won’t complain.
Now for some local variables. (from now on, I won’t show the import statement)
2
let start() be
{ let x = 5, y = 10, z;
x := x + 1;
z := x * (y + 1);
y +:= 2;
out("x=%d, y=%d, z=%d", x, y, z) }
• let introduces the declaration again. You know that x, y, and z are variables and
not functions because they are not followed by ().
• let is followed by any number of variable names all separated by commas. each
variable may be given an initial value (like x and y), or left uninitialised (like z).
• There can be any number of lets, you don’t have to declare all your variables on
one line.
• But lets are only allowed at the beginning of a block. All declarations must come
before any executable statement.
3
• := is the symbol for an assignment statement. Unlike in C++, you can’t give
yourself a hard-to-debug problem by accidentally typing = instead of ==.
• Assignments are statements, not expressions. := can not be used as an operator in
an expression.