Example scripts

Amber ships with a selection of simple scripts designed to illustrate various aspects of the use of Amber.

You can find the scripts in the examples directory of the Amber distribution, or you can browse them online by following the links to the development repository that are provided on this page.

Quick links:

hello

This is the traditional one-liner.

factorial and fibonacci

These examples show trivial use of recursion. The factorial example will move seamlessly from integers to "big numbers" if the big number library is installed.

indiana

This fun little application demonstrates the use of string manipulation, manifest arrays and agents (anonymous routines).

word_count

This program works like the Unix 'wc' utility. It counts the lines, words and characters in the file whose name is supplied on the command-line. The application shows how to access the command-line and to read from a file.

99 bottles of beer

This is an Amber script that prints the lyrics of the song "99 bottles of beer". You can see this application implemented in hundreds of different programming languages at the 99 bottles of beer website.

This application shows the use of agents, string catenation, routines with "is"-bodies, and the "If_expression" construct.

guessing_game

In this simple game, you guess a number in response to clues printed by the computer. (On my system, the Parrot random number generator gives three consecutives ones at the start, but then it appears to become more random.)

This application shows the use of loops with more than one exit.

regexp

Parrot's (and Amber's) regular expressions support the new Perl 6 Rules syntax. Whilst simple examples are similar to the regular expressions that we know and love, there are some differences.

This script lets you enter a regular expression, then see whether (and how) it matches against the strings that you enter.

game of life

This is an Amber implementation of Conway's "Game of Life", which shows how a grid of "living" and "dead" cells changes over time.

This script uses a fixed 40x20 gameboard, with a preset starting position. It defaults to 20 generations, but you can override this on the command-line.

amber-square

This is a minimal Amber gui application, which shows just how simple it can be. It displays an amber square for one second, then exits.

You will need to have the SDL libraries installed.

sh: /home/web/cgi/eiffelzone/comments.exe: No such file or directory