ⓘ Red (programming language)


ⓘ Red (programming language)

Red is a programming language designed to overcome the limitations of the programming language Rebol. Red was introduced in 2011 by Nenad Rakocevic, and is both an imperative and functional programming language. Its syntax and general usage overlaps that of the interpreted Rebol language.

The implementation choices of Red intend to create a full stack programming language: Red can be used for extremely high-level programming DSLs and GUIs as well as low-level programming operating systems and device drivers. Key to the approach is that the language has two parts: Red/System and Red.

  • Red is a homoiconic language capable of meta-programming, with semantics similar to Rebols. Reds runtime library is written in Red/System, and uses a hybrid approach: it compiles what it can deduce statically and uses an embedded interpreter otherwise. The project roadmap includes a just-in-time compiler for cases in between, but this has not yet been implemented.
  • Red/System is similar to C, but packaged into a Rebol lexical structure – for example, one would write if x > y instead of if x > y { printf "Hello \n ";}.

Red seeks to remain independent of any other toolchain; it does its own code generation. It is therefore possible to cross-compile Red programs from any platform it supports to any other, via a command-line switch. Both Red and Red/System are distributed as open-source software under the modified BSD license. The runtime library is distributed under the more permissive Boost Software License.

By version 0.6.4 Red includes a garbage collector "the Simple GC".


1. Introduction

Red was introduced in the Netherlands on February 2011 at the Rebol & Boron conference by its author Nenad Rakocevic. In September 2011, the Red programming language was presented to a larger audience during the Software Freedom Day 2011. Rakocevic is a long-time Rebol developer known as the creator of the Cheyenne HTTP server.


2. Features

Reds syntax and semantics are very close to those of Rebol. Like Rebol, it strongly supports metaprogramming and domain-specific languages DSLs and is therefore a highly efficient tool for dialecting creating embedded DSLs. Red includes a dialect called Red/System, a C-level language which provides system programming facilities. Red is easy to integrate with other tools and languages as a DLL libRed and very lightweight around 1 MB. It is also able to cross-compile to various platforms see Cross Compilation section below and create packages for platforms that require them e.g.APK on Android. Red also includes a fully reactive cross-platform GUI system based on an underlying reactive dataflow engine, a 2D drawing dialect comparable to SVG, compile-time and runtime macro support, and more than 40 standard datatypes.


3. Goals

The following is the list of Reds Goals as presented on the Software Freedom Day 2011:

  • Be "Green", Have a Small Footprint "Because resources are not limitless."
  • Compactness "Being highly expressive maximizes productivity."
  • Flexibility "Not best but good fit for any task!"
  • Portability, Write once run everywhere "That’s the least expected from a programming language."
  • Ubiquity "Spread everywhere."
  • Simplicity "An IDE should not be necessary to write code."
  • Speed "If too slow, it cannot be general-purpose enough."

4. Development

Reds development is planned to be done in two phases:

  • Initial phase: Red and Red/System compilers written in Rebol 2
  • Bootstrap phase: Red and Red/System compilers complemented by a Red JIT-compiler, all written in Red

5. Cross compilation

Red currently supports the following cross-compilation targets:

  • MS-DOS: Windows, x86, console and GUI applications
  • Windows: Windows, x86, GUI applications
  • Android-x86: Android, x86
  • Raspberry Pi: Linux, ARMv5, armhf hard-float
  • Linux-ARM: Linux, ARMv5, armel soft-float
  • Android: Android, ARMv5
  • FreeBSD: x86
  • Linux: Linux, x86
  • Syllable: Syllable OS, x86
  • Darwin: OS X Intel, console and GUI applications

Note: This list will increase with time and should therefore be considered as incomplete.


6. Factorial example

IMPORTANT: These are intended as syntax examples. Until Red has 64-bit support, the integer example will overflow a 32-bit integer very quickly. Changing that to `float!` will go farther, but these are merely to show the syntax of the language.

The following is a factorial example in Red:

The following is the same factorial example in Red/System in this very simple case, the source code is very similar to Reds version: