Qore Programming Language
=========================

This document provides an overview of the Qore programming language.

What is Qore?
-------------

Qore is a modular, multi-threaded, SQL-integrated dynamically typed scripting language with optional hard typing and procedural and object-oriented features, powerful and easy-to-use data types, structures, and operators, a clean and easy-to-lean/read syntax.


Why use Qore?
-------------

Qore was designed to provide a flexible vertical platform for business solutions and interface development.  Additionally, Qore was designed to be fun and efficient to program in.

Qore's vertical approach means that the language has been designed to be suitable for writing simple yet powerful scripts, as well as complex, multi-threaded, database integrated, network-aware applications.  Another important feature of Qore at the higher end is the ability for a Qore application to support embedding (and arbitrarily restricting) user-defined logic (also written in the Qore language).

Qore is highly threadable and has been designed to favor multi-threaded performance over single-threaded performance, this Qore programs are very scalable on machines with many processors.

Qore features exception handling similar to C++'s or Java's, but adapted for a weakly-typed language.

Qore is designed to facilitate dynamic/embeddable program logic where capabilities of the embedded logic units can be arbitrarily restricted, with particular emphasis on use in multithreaded contexts.

Qore includes built-in date operators & date arithmetic (eg: $a = now() - 1D - 5m will assign $a to the date and time one day and 5 minutes ago).

Qore's object-oriented support implements inheritance (polymorphism, with multiple inheritance and private inheritance), private members (data encapsulation), static members and support for dynamically extending functionality through special "memberGate", "methodGate", and "memberNotification" methods.  methodGate() and memberGate() methods allow accesses to non-existant members and methods to be transparently redirected in any way desired; the memberNotification() method allows objects to automatically react to external changes in public member states.

Support for exception-safe programming is facilitated with the on_exit, ex_error, and on_success statements, allowing code to be queued to be executed optionally depending on the exception status when the local block is exited, which allows programmers to place cleanup code right next to the code requiring the cleanup (instead of phyiscally separated and possibly in many nested blocks using try/catch - however please note that try/catch blocks are also supported by qore).

Qore has built-in national character set support based on the C library's iconv functions and supports both implicit and explicit character set conversions.  For example, if a Datasource object is assigned the "UTF-8" character set, but a File object has "ISO-8859-1" character set, any data written to the database from the File object will be automatically converted implicitly to the "UTF-8" character set without any intervention necessary by the programmer.

Qore's db modules (delivered separately) make it easy to write scripts/programs to manipulate data in different types of databases.
Furthermore the Datasource class offers an interface and constructs that facilitate database-independent development.

Qore has libxml2 integration, allowing simple, automatic, and transparent serialization/deserialization to/from XML data to/from Qore data structures.

Qore has JSON and JSON-RPC integration, supporting transparent serialization/deserialization to/from JSON data to/from Qore data structures.

Qore has Socket, HTTPClient, XmlRpcClient, JsonRpcClient, and FtpClient classes (all supporting optional TLS/SSL encryption) for easy communication with various protocols.

Qore uses the PCRE library to provide Perl-compatible regular expression support.


How does Qore compare to other programming languages?
-----------------------------------------------------

Qore's syntax superficially appears to be a mixture of C and perl with some unique features to Qore (such as context statements, etc).  However Qore is not perl; perl is a robust, mature, feature-full, and powerful language, and Qore is a new, young, and (compared to perl) relatively limited language and differs philosophically in some areas.  Qore's orignal syntax was inspired by perl's.  If you hate perl's syntax, then you will probably not like qore's either.  However, if you like perl, but dislike its threading limitations, then Qore may be the right language for you.

(Some) similarities to perl
* Qore is a weakly-typed scripting language (although supports strong typing as of v0.8 similar to perl6)
* Qore variable references begin with a dollar sign "$". (ex: $value is a valid variable in both perl and Qore)
* In Qore, subroutines are declared with the word "sub"
* Qore and perl share many statements (ex: for, foreach, while, do, if, etc)
* Qore and perl share many basic operators
* Qore and perl both use double-precision floating point numbers
* Qore uses PCRE (www.pcre.org) to provide perl5-compatible regular expression support
* Qore and perl support closures that encapsulate the state of local variables at a higher lexical level than the closure and accessed within the closure.  Qore has the advantage of supporting closures in a thread-safe way; even local variables accessed within the closure are thread-safe

(Some) differences from perl
* Qore has a clean and powerful threading model, built-in from the start by design
* Qore has clean object-oriented features, built-in from the start by design
* Qore has native UTF-8 support (qore's substr(), string splice, index(), etc work on character offsets, not byte offsets according to the character encoding used for the string), perl's wide character support is not as transparent - for example, 'printf("%s\n", substr("ä", 0, 1));' will output an invalid character in perl, but work properly in Qore using UTF-8 variable-width characters
* Qore tends to avoid syntactic shortcuts and require more verbose expressions than perl; Qore has a much smaller grammar than perl; ex: Qore has "if" statements, but no "unless"; etc
* A Qore variable can be of any type, whereas in perl the type of variable also depends on the name
	perl: @array = (1, "two"); %hash = ( "a", 1, "b", 2);   $scalar = 3.0;
	Qore: $array = (1, "two"); $hash = ( "a" : 1, "b" : 2); $scalar = 3.0;
* Qore subroutines can be declared with an optional list of local variables to receive subroutine arguments; the parentheses after the subroutine name are not optional in Qore.
* Qore accepts a statement or a statement block after if, while, for, foreach, etc, like C, C++, and Java, but unlike perl that requires a block ("{" "}") after such statements
* Qore's splice operator works on strings (repecting character offsets for multi-byte character encodings) as well as lists
* Qore has a switch/case statement, whereas perl has none
* Qore hashes must be specified with a specific syntax ( "key" : <value expr.> )
* Qore's object-oriented features are very different from perl's.
* Qore's exception handling is more similar to C++ or Java's.
* Qore has very tight database integration and syntactic support for processing query results (context statements, find expressions)
* Qore uses 64-bit integers by default
* Qore's operators can change lvalues without references, in Qore a function can change an lvalue only if a reference is passed
* there is currently no generic equivalent to perl's references.  It is only possible to pass values by reference in Qore if the subroutine includes a local variable argument list
* Qore does not support variable substitution from regular expressions, in qore you need to construct the regex strings manually and use the regex() or regex_subst() functions
* Qore supports safe signal handling as well
* Qore supports subpattern extraction from a regular expression when the x// operator is used (i.e. $list = "xmlns:wsdl" =~ x/(\w+):(\w+)/ will result in $list = ("xmlns", "wsdl") ) whereas perl uses the $1, $2, ... automatic variables
