Home page

logo Getting started

I do not plan to write detailed tutorials, just a collection of examples to play with.

What I recommend you do is bring up the official online documentation while you are playing with the examples -- it has a popup window that enables rapid navigation to information on any of the keywords:

Create a blank file, say demo.bac, and click on it to open with NicoEdit (or any other editor that uses Gtksourceview and can thus display BaCon code with color syntax highlighting). Then start playing...

Simple variables and printing


You can type in the above a few lines at a time, compile and test. To compile and test:
# bacon demo.bac
# ./demo
This code shows how simple variables and numbers are. Notice a, e and b$ -- these are the three types, FLOATING, NUMBER and STRING. NUMBER is an integer. You don't have to declare them beforehand, they get created when first used in the code. STRING variables always have a '$' suffix. NUMBER is a signed 32-bit integer and FLOATING is a 64-bit floating point number.

If those three data types are not good enough for you, you can declare any C datatype, by means of the GLOBAL and LOCAL keywords. See above, I declared c as type 'char'.

Play with the printing. Note above, the ';' suppresses a carriage-return. To print multiple items with the one PRINT statement, use a ',' separator.

BaCon is very C-like in it s datatypes, because it is really just a thin shell on top of the Gnu C compiler. The PRINT statement can have an optional FORMAT statement that works just like formatting does in C.

One little thing: note the line c='z'. I used single-quotes to assign a single character, same as you would do in C. If I had followed that by PRINT c, it would print 122, the numeric value, but by the FORMAT qualifier I can make it print as a character (%c).


Simple mathematics

Flow control

© Copyright Barry Kauler 2010 bkhome.org All rights reserved
See FAQ for legal statement.