logo
The Falcon Programming Language
A fast, easy and powerful programming language
Location: Home page >> Falcon wiki
User ID:
Password:
 

Falcon Wiki - Survival:Introduction


Introduction

Falcon is what is commonly known as a scripting language ; program source code is simply referred as the "script". The script is organized into lines that are executed one after another (empty lines being ignored). Every line is interpreted as a command, or more properly, as a statement. The most basic statement is the assignment , which allows storing a value into a variable. A variable is exactly that: a temporary storage for a value. Meet our first falcon script:

number = 0 

This is an assignment storing the value 0 into the variable named number . Variable names must start with a lower case or uppercase letter, with a _ underline sign or with any international character; after that you may use any letter or number, and the "_" underline sign. Some examples of valid names: number, _Aname, variable_number_0.

Falcon understands symbol names in any language of the world. For example , the number we have seen above may be written in Chinese:

数 = 0 

Falcon provides three elementary value types: integer numbers, floating point numbers and strings. Integer numbers include 0, 1, 2 and also -1, -2, -3 and so on. Floating point numbers are numbers that contain a floating point; i.e. 1.2, 0.001, or scientific notation numbers such as 1.34e15, indicating 134 followed by 13 zeros. Falcon also supports hexadecimal and octal numbers in standard C notation (0x. and 0.); explaining what hexadecimal and octal numbers are is beyond the scope of this text (and if you don't know what they are, then you don't need them).

Strings are sequences of characters enclosed with double quotes, like this: "this is a string" . Strings may span across multiple lines; and in that case any blanks or tabs before the first character will be removed.

An element that is quite important in every programming language is the comment. Comments are pieces of text that are completely useless to the program, but that can be used to write information, warnings or just notes in the text. Falcon supports C-language style single line and block comments. A single line comment begins with two slashes (//) and ends at the end of the line. A block comment begins with a slash followed by an asterisk, and terminates when an asterisk followed by a slash is met (/*...*/). Many programmers love to mark code areas with lots of asterisks or slashes. So, we are ready to see how a Falcon script may look like:

/********************************* 
   My First falcon Script
*/ 
 
var1 = 156                  // An integer number
var2 = 1e15                // A scientific notation number  
var3 = "Hello World"   // A string
 
//////////////////////////// end of the script 

 

Falcon supports the "execute script" pre-processing directive for Unix shells: if the first line of the script begins with a pound sign (#) the line is ignored by Falcon . Its use is to indicate to the shell that it's the Falcon interpreter that is to execute the script, i.e. #!/usr/bin/falcon

Other than comments, statements and elementary constants, the last Falcon basic brick is the expression . An expression is a set of elementary constants, variables or simpler expressions connected via operators. Here are some examples:

number = 10 
sum = number + number 
value = number * sum * 5 + 2 
complex_value = value * (number + 1.2 ) - 15 * (sum/3.15) 
sum_of_string = "A string" + " "+ "and another" 

Falcon provides a number of operators that work on strings. For example , summing a string to another, or to a variable which contains a string, will result in new strings containing the two original strings joined together.

The mathematical operators that Falcon supports are addition (+), subtraction (-), multiplication (*), division (/), power (**) and modulo (%). The power operator can take a fractional number as a second operand; in this way it's possible to perform arbitrary roots. For example , 100 ** 0.5 will give 10 as result. The modulo operator can be applied to two integer numbers ONLY and gives the remainder of their division; for example , 10 % 5 is 0, while 10 % 3 is 1 (because 3*3 = 9, and 10 - 9 = 1). Applying the modulo operator to non-integer numbers will cause an error to be raised.

Falcon also supports "self operators"; they are +=, -=, *=, /=, **= and %=. Self operators assign to a variable the operations they represent using the same variable value in the operation. For example:

number = 10 
number += 1 

will cause {number} to become 11.

Falcon also provides ++ and -- operators.  Both prefix and postfix operators are supported.

One particularly important expression in Falcon is the function call . Function calls are composed of a symbol near two round brackets which can contain a list of parameters , each of which may be an expression and separated by commas. Like this:

number = 10 
printl( "The square of 10 is: ", number * number )

We just met our first function: printl. This function prints all of its parameters and then advances the cursor to the next line. Another function, named print, just prints all the parameters without advancing the cursor to the next line.

print and printl are actually using the virtual machine standard output stream to perform output. This stream can be managed by the embedding application, redirected to files, and encoded through Unicode or through other encodings.

Functions may "return a value"; print and printl do not return any value, but a function that returns a value may be used as a part of an expression, like this:  

number = 10 * a_function_of_some_kind( 10 ) 

As variables, function names may be written in any language. For example, the following sentence in Japanese is correctly understood in Falcon:

かず = 10 * 例え_ファンクチオン( 10 )

Your first Falcon script

It's time to execute your first Falcon script. To do this, write the following lines in a text editor (i.e.  Notepad), save the file as first.fal and enter a console (also known as "Ms-Dos" prompt, or "cmd" prompt). To do this, you are supposed to know how to access the console and change the directory. Minimal survival instructions for Windows-users are: press "start" and select "execute command". If you are running Windows 95, 98, or ME write "command" in the box that appears on the screen; if you are running Windows NT, 2000 or XP write "cmd". Press enter, and voilà. Under Linux, for example, just open up a Terminal. Finally, launch Falcon with the command "falcon first.fal". Here is the code for first.fal: 

/************************************* 
* First Falcon program: first.fal 
* This is just a comment; its content 
* does not matter, is just here to
* remind you that this was your first 
* Falcon script ever. 
**************************************/ 
 
> "Hello world." 

When a line begins with > what follows is sent to the output stream and a newline character is added. This is called called fast print, as opposed to other methods to write output (for example, through the printl() function that has been shown before).

A line may begin with >> alone, in which case what follows is sent to the Falcon output stream, but without appending a final end-of-line (EOL) character.


Navigation
Go To Page...

Loading

Elapsed time: 0.032 secs. (VM time 0.027 secs.)