the Zimbu programming language

Navigation

Home

Suppose you want to write a new program, something like a text editor.  What language would you write it in?
  • It has to be as fast as possible, so interpreted languages are out.
  • You don't want to micro manage memory, so C is out.
  • You don't want to require programmers to have a degree, so C++ is out.
  • You want fast startup and not depend on a big runtime, so Java is out.
  • It has to run on most systems, anything with a C compiler, so D is out.
  • You want to have fun making something new.
No existing language really meets these demands, so let's create a new one that does.

Zimbu is an experimental programming language.  It is a very practical, no-nonsense kind of language.  It mixes the good things of many existing languages and avoids their deficiencies.  And then throws in a few brand new ideas.


Goals are (more on the Goals page):
  • easy to read back - code is read N times more often than it is written
  • avoid common mistakes - make it difficult to write bad code (but you can write hacks if you really want to)
  • keep it short and clear, don't state the same thing twice - no header files, don't repeat type specs
  • the effect of a statement should be predictable and not depend on something in another file
  • efficient execution: no startup delay, reasonable memory use - no Just In Time compiler effects
  • support a wide range of applications - Zimbu can be used to write an OS kernel, a short script and a big GUI application
  • portable - be able to compile and run on almost any system
  • many standard data types, modules and classes - most things you need are already there
Main choices made so far (more on the design page):
  • convert the program to C and use the C compiler to produce machine code (could be something else later)
  • mostly use static type checking, also allow runtime type checking
  • object oriented, all data is handled like an object, but there also are individual functions
  • code files can contain one module and several classes, organize packages in directories
  • the standard modules and classes are available without imports, avoids boring work
  • many modules are part of the language, they work the same way everywhere
  • all keywords are in capitals, you can use all other names without worrying about the next version breaking your program
Status:
  • The compiler can compile itself and run a few tests.  The examples below run properly.
  • The source code includes too many hacks for public viewing (embarrassment factor).
  • This website is only just a start, much more to follow.

Examples

The Hello World example, hello.zu:

MAIN()
  IO.write("Hello, World!\n")
}

Notes:
  • The entry point to the program is the MAIN() function.
  • Keywords are in all capitals, this avoids the problem that you need to know all keywords when picking a name.
  • The IO module contains I/O stuff.  IO.write() writes to stdout.  IO.stdout.write() would do the same.  In Zimbu things that you use often are kept short.  The long form is available for consistency.
  • The IO module is part of the language, no need to import it, we know where it is.
  • "\n" is a newline character. String escape characters are used like in C and Java.
  • There is no semicolon to end or separate statements.
  • The } character is used to end a block.  There is no {, we know where the block starts.  This avoids useless discussions about where to put the {.

The Unix style "echo" program in Zimbu, echo.zu (line numbers added for reference, they are not part of the file):

 1 # Zimbu example program: Unix style "echo"
 2
 3 MAIN()
 4   Bool    writeNewline = TRUE
 5   String  sep = ""
 6   Bool    didFirst
 7   FOR arg IN ARG.getAll()
 8     IF !didFirst && arg == "-n"
 9       writeNewline = FALSE
10     ELSE
11       IO.write(sep + arg)
12       sep = " "
13     }
14     didFirst = TRUE
15   }
16   IF writeNewline
17     IO.write("\n")
18   }
19 }

Let's explain this line by line.

 1 # Zimbu example program: Unix style "echo"
Comments start with the # character and continue until the end of the line.

 3 MAIN()
The entry point to the program.  There are no arguments here.  Command line arguments are handled by the ARG module and are available everywhere.  This avoids having to pass them around and creating dependencies.

 4   Bool    writeNewline = TRUE
This declares the variable writeNewline as a Boolean type and initializes it to true.  Zimbu is statically typed, which means the compiler will check that writeNewline will always be used as a Boolean.  One can use the type ANY if type checking is to be done at runtime.

 5   String  sep = ""
This declares the variable sep (short for separator) as a String type and initializes it to an empty string.

 6   Bool    didFirst
This declares the variable didFirst as a Boolean type.  There is no explicit initialization, the default value FALSE is used.  All variables are initialized to zero, FALSE or NIL by default.

 7   FOR arg IN ARG.getAll()
Oh my, a lot is going on in this line.  The basis is a FOR arg IN iterable statement.  It iterates over all the elements in the list, assigning the value of each element to arg in turn.  Much like Python.

The list in this case is obtained with ARG.getAll().  This is the list of all command line arguments.  The ARG module actually has nicer ways to deal with flags, but since the echo command is very specific about how it handles arguments we need to avoid, for example, accepting a --help argument.

The loop variable is arg.  It was not declared yet and therefore it happens here automatically. This is one of the few places where you can use a variable without declaring it. The scope of arg is the FOR loop only.

The type of the variable arg is obtained from the iterable list.  Thus it is statically typed, but we don't need to specify the type explicitly.  In this case the type comes from the return value of ARG.getAll(), a list of Strings.

 8     IF !didFirst && arg == "-n"
A conditional statement.  Parenthesis around the expression are not required.  The expression syntax resembles C and Java.  But string values can be directly compared with ==.  To compare object identity IS can be used, like in Python.

 9       writeNewline = FALSE
The "-n" argument was found, reset writeNewLine so that we omit writing the newline at the end.

10     ELSE
The else part of the IF statement.  It also separates the two blocks of statements, no { or } is required.

11       IO.write(sep + arg)
The + operator can be used to concatenate strings.

12       sep = " "
Next time we write an argument the prepended separator is one space.

13     }
The end of the IF statement.

14     didFirst = TRUE
Now we are no longer at the first argument.  Next time we will not check for a "-n" argument.  This is consistent with the Unix echo command: "echo -n -n hello" writes "-n hello".

15   }
The end of the FOR loop.

16   IF writeNewline
17     IO.write("\n")
18   }
When writeNewline is true write the final newline.

19 }
Ends the MAIN() function block.