Skip to content
📖 A Byte of AutoBook contents

First Steps ​

We will now see how to run a traditional "Hello World" program in Auto. This will teach you how to write, save, build and run Auto programs.

Unlike Python, Auto uses a compile-run workflow: you write your source code in an .at file, use the auto b command to transpile it to Python via the a2p transpiler, and then run the resulting Python file. Let us explore how this works.

Using the Command Line ​

Open a terminal in your operating system (as discussed in the Installation chapter) and navigate to a directory where you would like to keep your Auto projects. For example:

console
$ mkdir ~/auto-projects
$ cd ~/auto-projects

You can verify that the Auto toolchain is ready by running:

console
$ autoc --version

You should see the version number printed to the screen, confirming that everything is installed correctly.

How to Quit ​

There is no interactive interpreter to quit -- Auto is a compiled language, not a REPL. If a running program gets stuck, you can press Ctrl + C in the terminal to interrupt it. To exit the terminal itself, type exit or press Ctrl + D (on Linux and macOS).

Choosing An Editor ​

We need an editor to write and save our Auto source files. A good programmer's editor will make your life much easier. You have to choose an editor as you would choose a car you would buy. A good editor will help you write Auto programs easily, making your journey more comfortable and helping you reach your destination much faster and safer.

One of the very basic requirements is syntax highlighting where all the different parts of your Auto program are colorized so that you can see your program and visualize its running.

Here are some recommendations:

  • VS Code with the Auto extension -- this is the most beginner-friendly option. VS Code is free, available on Windows, macOS and Linux, and provides excellent Auto support including syntax highlighting and IntelliSense.
  • Vim or Neovim -- a powerful, terminal-based editor favored by experienced programmers. If you already know Vim, you will feel right at home.
  • Emacs -- another powerful editor with a long history. Emacs users tend to be very passionate about their editor.

If you have no idea where to start, I would recommend using VS Code with the Auto extension.

Note: Whichever editor you choose, make sure it supports Auto syntax highlighting. This will help you spot errors much more easily as you type.

Using A Source File ​

Now let's get back to programming. There is a tradition that whenever you learn a new programming language, the first program that you write and run is the "Hello World" program -- all it does is just say "Hello World" when you run it. As Simon Cozens[^1] says, it is the "traditional incantation to the programming gods to help you learn the language better."

Start your choice of editor, enter the following program and save it as hello.at.

Filename: hello.at

Your first Auto program

Where should you save the file? To any folder for which you know the location of the folder. If you don't understand what that means, create a new folder and use that location to save and run all your Auto programs:

  • ~/auto-projects on macOS and Linux
  • C:\auto-projects on Windows

Note: Always ensure that you give your Auto files the .at extension, for example, hello.at.

Building and Running ​

To build and run your Auto program:

  1. Open a terminal window (see the previous Installation chapter on how to do that)
  2. Change directory to where you saved the file, for example, cd ~/auto-projects
  3. Create a pac.at package file in the same directory (or use the auto init command to generate one)
  4. Run the build command by entering auto b. This transpiles your Auto code to Python and then runs it.
console
$ auto b

You should see the following output:

text
Hello, World!

If you got the output as shown above, congratulations! -- you have successfully run your first Auto program. You have successfully crossed the hardest part of learning programming, which is, getting started with your first program!

In case you got an error, please type the program exactly as shown above and run the build command again. Note that Auto is case-sensitive i.e. print is not the same as Print -- note the lowercase p in the former and the uppercase P in the latter.

How It Works

An Auto program must have a fn main() function as its entry point. The a2p transpiler converts this into a Python def main(): function and automatically adds the standard if __name__ == "__main__": main() guard. Inside main, we call the print function and supply it with the text "Hello, World!", which is then printed to the screen.

Getting Help ​

If you need quick information about any Auto tool or command, you can use the built-in --help flag. For example:

console
$ autoc --help

This will display usage information for the autoc compiler, including all available options and flags.

console
$ automan --help

This shows help for the automan package manager.

console
$ a2p --help

This shows help for the a2p transpiler, including its various options for controlling the transpilation process.

For detailed documentation, you can visit the official Auto website at <https://auto.dev>.

Summary ​

You should now be able to write, save, build and run Auto programs at ease.

Now that you have written your first Auto program, let's learn some more Auto concepts in the next chapter.


[^1]: the author of the amazing "Beginning Perl" book

Released under the MIT License.