The Falcon Programming Language: a brief tutorial

Status
Not open for further replies.

Kharn

Lord Techie,
Messages
7,638
A comprehensive overview of a programming language designed as a mixture of programming styles.


The Falcon Programming Language is a typeless language born for rapid development, prototyping, and ready-made integration. We may also describe Falcon as a “scripting” language with features that enable the programmer to create even complex multi-threaded applications. It mixes several different programming paradigms into an unique blend of constructs, overcoming the limitations and partialities of other languages.
The objective of this brief article is to be very practical with code examples as well as step by step simple instructions. I won't reprise the historical and technical details that led us to developing this new programming language. Please feel free to visit the main Falcon Programming Language site The Falcon programming language for plenty of details.
The Falcon p. l. presents multiple programming paradigms with a unique blend of interconnected concepts. Procedural, functional, both prototype and class based-object oriented, message oriented and tabular programming. Each of these extending into the others gives you the freedom to choose the perfect blend to represent the problem at hand. Falcon allows you, the programmer and the real human, to overcome the limitations of many programming languages that force you to restrict your thinking. Falcon allows you to just follow the flow of your thoughts. “Apply Mind over matter” is the motto for Falcon. It is not the programmer's mind that must reduce down to the simplified representation of the design, forced by single-minded programming languages, regardless of how mathematically elegant those representations may be. It is the language that must cope with the complexities of a non-linear thought. Falcon gives human thought the means to express itself via the computer paradigm. We feel that Falcon may be the cure for the common computer.
The Basics

Falcon has native strings, numbers, arrays and dictionaries. Falcon has a set of single line and block (multi line) imperative statements. Since version 0.8.12, Falcon provides an experimental interactive mode, useful for fast tests and for learning the expressions in this new language. We can jump right in with a tutorial with the command “falcon -i”. You are now in interactive mode where the following code can be entered:
array = ["Have", "a", "nice", "day"] // (1)
for elem in array // (2)
>> elem // (3)
formiddle // (4)
>> " "
end

forlast
> "!" // (5)
end
end Here is what you will see on the command line of your OS (Solaris is used in this example):
bash-3.2$ falcon -i
Falcon compiler and interpreter.
Version 0.8.14.2 (Vulture)

Welcome to Falcon interactive mode.
Write statements directly at the prompt; when finished press CTRL+D to exit
>>>
>>> array = ["Have", "a", "nice", "day"]
: Array
>>> for elem in array
... >> elem
... formiddle
... >> " "
... end
... forlast
... > "!"
... end
... end
Have a nice day!
>>> We have just created an array of strings in line (1). Then we iterate (2) over the list taking one element at a time and printing on the standard output (3). The double greater-than symbol “>>” prints the given item to the standard output; the single “>” will add also a new-line.
The for/in block is divided into four regions, three of which are optional; the forfirst area (executed when the loop is started and just once), the main area (always executed), the formiddle area (executed after the main area for all the elements except the last) and the forlast area (executed after the main area for the last element has completed).
All Falcon block statements can be shortened in case they contain just one statement through the “:” symbol. So, we may re-write the above loop in a more compact way (and adding a forfirst block) :
for elem in array
forfirst: >> "Contents of the array: "
>> elem
formiddle: >> " "
forlast: > "!"
end Here is what you will see on the command line of your OS (Solaris again):
bash-3.2$ falcon -i

Falcon compiler and interpreter.
Version 0.8.14.2 (Vulture)

Welcome to Falcon interactive mode.
Write statements directly at the prompt; when finished press CTRL+D to exit
>>> array = ["Have", "a", "nice", "day"]
: Array
>>> for elem in array
... forfirst: >> "Contents of the array: "
... >> elem
... formiddle: >> " "
... forlast: > "!"
... end
Contents of the array: Have a nice day!
>>> As in the vast majority of modern languages, functions can be called by applying parenthesis to a symbol; print and printl are two functions equivalent to “>>” and “>”, fast-print operators respectively, we can write:
for elem in array
forfirst: print( "Contents of the array: " )
print(elem)
formiddle: print( " " )
forlast: printl( "!" )
end But a very important working principle of Falcon is that computational units (functions) are actually expressions; as such, we can be a bit fancy and pick the best function to employ as the result of an expression:
for i in [ 0 : array.len() ] // (1)

/* A bit naive, but this is just a sample */
if i == array.len() - 1 // (2)
separator = "!"
else
separator = " "
end
// (3)
( i != array.len()-1 ? print : printl ) \
( array, separator )
end In (1), the code performs a loop in a “range”, declared as [n:m]; the i variable gets the values between n and m-1 ( one less than m ). In (2) there is a simple “if” statement in which we assign a space or a terminal character to the variable “separator”. This simply depends on the value of “i” in this loop and clearly we are looking for the last element in the array. Then, we see the principle at work in (3). The ternary if, <a> ? <b> : <c> expression can either resolve in the “print” (if i is not array.len() ) or printl value, which is immediately called with two parameters: the i-th element in the array and the separator. Both functions print all the parameters they receive, and so we see another important principle of Falcon: computational units can be called with an arbitrary number of parameters. Parameter binding is resolved (efficiently) at runtime, and many functions are prepared to receive different parameter sequences.
Falcon also has a wide set of “standard” statements:

  1. the “while” loop,
  2. if-elif-else,
  3. break/continue statements in loops,
  4. a powerful “switch/case” statement
  5. and many more …
We are skipping them right now, as they do nothing unexpected or extraordinary (well, not quite; many, as the “continue dropping” statement, have received some power ups in Falcon). We'll see some of the most interesting and peculiar statements as we continue the exposition of the conceptual Falcon framework.


Full article and Source.
 
Thank you, thought it would be good to get this some exposure the author really did his home work.
 
Status
Not open for further replies.
Back
Top Bottom