Qore Programming Language Reference Manual  0.9.15
Introduction

Introduction to Qore

The Qore programming language is a powerful, thread-capable, embeddable weakly-typed language with optional strong typing and procedural and object-oriented features designed for anything from quick scripting to complex multithreaded, network-aware application development to embedded application scripting. Qore was initially designed to facilitate the rapid implementation of sophisticated interfaces in embedded code in an enterprise environment, and has since grown into a general-purpose language as well.

Qore exports a C++ API to allow programs or libraries to embed Qore code; this manual documents Qore's user-level features, for more information about Qore's C++ API, see the Qore home page.

Flexible character encoding support is also built-in to Qore strings, and automatic character encoding conversions are supported, enabling correct behavior when working in an environment with mixed character encoding requirements (see Strings and Character Encoding).

Qore includes the following design points:

Support for Embedded Logic
Qore was designed to support embedding logic in applications; this also applies to applications written in Qore as well as applications using the Qore library's public C++ API. By using the Program class, discrete objects can be created and destroyed at will containing embedded code to extend or modify the behavior of your application in user-defined ways. The Program class allows the capabilities of embedded code to be arbitrarily restricted as well.

Thread Safety and SMP Scalability
All elements of Qore are thread-safe, and the language in general has been designed with SMP scalability in mind. The internal design and implementation of Qore favors multithreaded performance over single-threaded performance, so multithreaded Qore programs can count on an efficient and stable execution platform, and do not have to limit themselves to a subset of Qore's functionality (see Threading). Additionally, Qore includes optimizations designed to reduce the number of SMP cache invalidations that provide a substantial performance boost on SMP machines.

Qore supports deadlock detection in complex locking scenarios and will throw an exception rather than allow an operation to be performed that would cause a deadlock. Furthermore, Qore's threading primitives detect threading errors and throw exceptions in these cases as well.

Database Integration and DBI Layer
Retrieving, comparing, and manipulating data in a consistent manner from heterogenous database types is made possible by Qore's built-in database integration. Qore was designed with a database independent interfacing (DBI) layer, providing a standard interface for Qore programs to access any database supported by a Qore DBI driver (see the Datasource class). Qore now supports a very high level API in SqlUtil, which provides facilities for automatic schema management and programmatic SQL generation as well as data synchronization between heterogenous database types and more.

Function and Class Library
Qore's basic functionality covers areas such as: POSIX-compliant command-line parsing (ex: GetOpt class), strong encryption and digest calculation, thread synchronization (ex: Queue class, Mutex class, Condition class, etc), working with files (File class), socket, HTTP, and higher-level protocol communication (Socket, HTTPClient, FtpClient classes, optionally with TLS/SSL encryption), support for dynamic embedded application logic (Program class). Additionally, Qore's functionality is extended with modules delivered separately from the Qore library (see Module Description or Qore's home page for more information.

Familiar Syntax
Qore syntax is similar to other programming languages, allowing new programmers to rapidly come up to speed in Qore. Qore borrows features from languages such as: C++ (ex: multiple inheritance, exception handling, static methods), Java (ex: the synchronized keyword, the instanceof operator, object and class implementation), Perl (ex: the foreach statement, splice, push, pop, chomp, trim operators, perl5-compatible regular expressions, and more), the D Programming Language (the on_exit, on_success, and on_error statements provide exception-aware functionality similar to D's scope(exit), scope(failure), allowing exception-aware cleanup code to be placed next to the code requiring cleanup), Python (range(), xrange(), and the RangeIterator class), and others, also with many features unique to Qore. Furthermore, Qore supports closures (including binding local variables in the closure in a way that is safe to use even in multithreaded contexts) and features for advanced list processing (map, foldl, foldr, and select).

Qore's operators are designed to produce the expected results for the programmer even when data types are mixed, a feature meant to further flatten the learning curve for new programmers.

Simple Resource Management
Qore's garbage collection approach is unique and allows Qore to support the RAII idiom for resource management with deterministic collection and destruction of objects even when objects participate in recursive directed graphs; see Garbage Collection and Resource Management for more information.

Additionally, every effort is made to find and fix bugs in Qore before every release; for example valgrind is used on Linux and OSX and dbx on Solaris to check for memory leaks and memory errors. Particular attention is paid to thread-safety of all Qore components as well; Qore aims to be a stable platform for enterprise development supporting both quick script-based solutions and as an encapsulating language for embedding (and protecting) code in a server application.

Note
Qore is moving toward establishing %new-style as the default syntax; all examples given in the Qore documentation are given assuming %new-style.