The Falcon Programming Language in a Nutshell
In late 2003, I had the problem of making business-critical decisions and performing maintenance actions in real time, analyzing data that was passing through the servers I was charged with controlling. Data throughput was on the order of thousands of messages per second, each of which was made of complex structures and possibly nested maps, whose size was measured in kilobytes.
The applications in charge of those controls were already almost complete, and they were heavily multithreaded by design. The only thing missing was the logic-processing engine. That would have been the perfect job for a scripting language, but the memory, CPU, threading, responsiveness and safety constraints seemed to be a hard match.
After testing the available solutions, I decided to try to solve the problem by writing a scripting language from the ground up, taking into consideration those design constraints. After the decision was made to move forward, useful items commonly found missing from other scripting languages were added to the design specification. So, Falcon mainly was designed from the beginning to meet the following requirements:
Rapidly exchange (or use directly) complex data with C++.
Play nice with applications (especially with MT applications) and provide them with ways to control the script execution dynamically.
Provide several programming paradigms under the shroud of simple, common grammar.
Provide native multilanguage (UTF) support.
Provide a simple means to build script-driven applications, easily and efficiently integrated with third-party libraries.
As soon as I was able to script the applications that drove the initial development and meet these ambitious targets in terms of overall performance, I realized that Falcon may be something useful and interesting for others also, so I went open source.
The project is now reaching its final beta release phase, and Falcon has become both a standalone scripting language and a scripting engine that can drive even the most demanding applications.
The Falcon programming language now is included with many high-profile distributions, including Fedora, Ubuntu, Slackware, Gentoo and others. If your distribution doesn't include it yet, you can download it from www.falconpl.org, along with user and developer documentation.
Falcon currently is ported for Linux (32- and 64-bit), Win32 and Solaris (Intel). Older versions work on Mac OS X and FreeBSD. We are porting the newer version shortly, and a SPARC port also should be ready soon.
Falcon is an untyped language with EOL-separated statements and code structured into statement/end blocks. It supports integer math (64-bit) natively, including bit-field operators, floating-point math, string arrays, several types of dictionaries, lists and MemBuffers (shared memory areas), among other base types and system classes.
Morphologically, Falcon doesn't break established conventions, for example:
function sayHello() printl( "Hello world!") end // Main script: sayHello()
You can run this script by saving it in a test file and feeding it into Falcon via stdin, or by launching it like this:
$ falcon <scriptname.fal> [parameters]
We place great emphasis on the multiparadigm model. Falcon is based on an open coding approach that seamlessly merges procedural, object-oriented, functional and message-oriented programming. We're also adding tabular programming, sort of a multilayer OOP, but we don't have the space to discuss that here. Each paradigm we support is generally a bit “personalized” to allow for more comfortable programming and easier mingling with other paradigms.
Falcon procedural programming is based on function declaration and variable parameters calls. For example:
function checkParameters( first, second, third ) > "------ checkParameters -------" // ">" at line start is a short for printl if first > "First parameter: ", first end // ... and single line statements // can be shortened with ":" if second: > "Second parameter: ", second if third: > "Third parameter: ", third > "------------------------------" end // Main script: checkParameters( "a" ) checkParameters( "b", 10 ) checkParameters( "c", 5.2, 0xFF )
You can use RTL functions to retrieve the actual parameters passed to functions (or methods). Values also can be passed by reference (or alias), and functions can have static blocks and variables:
function changer( param ) // a static initialization block static > "Changer initialized." c = 0 end c++ param = "changed " + c.toString() + " times." end // Main script: param = "original" changer( param ) > param // will be still original changer( $param ) // "$" extracts a reference > param // will be changed p = $param // taking an alias... changer( $param ) // and sending it > p // still referring "param"
Again, RTL functions can be used to determine whether a parameter was passed directly or by reference.
The strict directive forces the variables to be declared explicitly via the def keyword:
directive strict=on def alpha = 10 // we really meant to declare alpha test( alpha ) // call before declaration is allowed function test( val ) local = val * 2 // error: not declared with def! return local end
Falcon has a powerful statement to traverse and modify sequences. The following example prints and modifies the values in a dictionary:
dict = [ "alpha" => 1, "beta" => 2, "gamma" => 3, "delta" => 4, "fi" => 5 ] for key, value in dict // Before first, ">>" is a short for "print" forfirst: >> "The dictionary is: " // String expansion operator "@" >> @ "$key=$value" .= "touched" formiddle: >> ", " forlast: > "." end // see what's in the dictionary now: inspect( dictionary )
Notice the string expansion operator in the above code. Falcon provides string expansion via naming variables and expressions and applying an explicit @ unary operator. String expansions can contain format specifiers, like @ "$(varname:r5)", which right-justifies in five spaces, but a Format class also is provided to cache and use repeated formats.
Both user-defined collections and language sequences provide iterators that can be used to access the list traditionally. Functional operators such as map, filter and reduce also are provided.
|Happy Birthday Linux||Aug 25, 2016|
|ContainerCon Vendors Offer Flexible Solutions for Managing All Your New Micro-VMs||Aug 24, 2016|
|Updates from LinuxCon and ContainerCon, Toronto, August 2016||Aug 23, 2016|
|NVMe over Fabrics Support Coming to the Linux 4.8 Kernel||Aug 22, 2016|
|What I Wish I’d Known When I Was an Embedded Linux Newbie||Aug 18, 2016|
|Pandas||Aug 17, 2016|
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Happy Birthday Linux
- Vi IMproved--Vim and Happy Hacking Keyboard Lite 2
- ContainerCon Vendors Offer Flexible Solutions for Managing All Your New Micro-VMs
- What I Wish I’d Known When I Was an Embedded Linux Newbie
- Updates from LinuxCon and ContainerCon, Toronto, August 2016
- Tech Tip: Really Simple HTTP Server with Python
- New Version of GParted
- NVMe over Fabrics Support Coming to the Linux 4.8 Kernel
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide