Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learn Red ? Fundamentals of Red
Learn Red ? Fundamentals of Red

Learn Red ? Fundamentals of Red: Get up and running with the Red language for full-stack development

Arrow left icon
Profile Icon Ivo Balbaert
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (2 Ratings)
Paperback May 2018 252 pages 1st Edition
eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Ivo Balbaert
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (2 Ratings)
Paperback May 2018 252 pages 1st Edition
eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learn Red ? Fundamentals of Red

Red's Mission

In this chapter, we take a look at the main characteristics of Red, more specifically, what makes Red stand out compared to other programming languages. This will motivate you to start learning Red. Don't worry if some statements are a bit abstract at this stage; they will become clearer when we start using Red in the following chapters. It may be a good idea to come back to this chapter later.

We will cover the following topics:

  • A short history of Red
  • What makes Red special?
  • Red's main features

Technical requirements

A short history of Red

Red is an open source, modern programming language and platform, designed and developed by Nenad Rakocevic. Red started out in early 2011 and is now at Version 0.6.3 (with 0.6.4 coming in the near future), aiming for a 1.0 release in the next year or so. In order to better understand its features, we have to explore its name and history a bit.

What Red stands for

Red is short for Red[uced] REBOL, and that's why Red users proudly call themselves reducers. This points to two things:

  • Red builds upon REBOL, a language that gained some fame around the millennium and was built by Carl Sassenrath. In fact, Red is syntactically and semantically a 95% clone of REBOL, but tries to improve and enhance it where possible. This also means REBOL scripts can be easily converted to Red.
  • Red (like REBOL) wants to reduce today's code complexity—it aims to have compact runtime environments and dependencies (around 1 MB), instead of the hundreds of MB of the Java or .NET platform.

Some history

Development of Red started out with Red/System—this is a low-level language (like C) to enable programming at the full system level. Red/System is like an older sibling—it looks very much like Red, but it is aimed at lower-level programming so it is more restricted. We'll come back to it in Chapter 10, Advanced Red.

Gradually, Red evolved this foundation, adding with each release more and more data types, actions, and functions. A REPL interactive coding console, execution on ARM processors, a parsing engine, a cross-platform GUI dialect (working on Windows and macOS, and nearing completion on Linux and Android), reactive programming, and macros are among the hallmarks of this evolution.

From January 2015, the Fullstack Technologies company was formed to continue Red's ongoing development, together with an ever-growing community of open source contributors. The company raised capital from InnovationWorks and GeekFounders (Chinese VC early-stage investors) and has its headquarters in Beijing's Silicon Valley.

In January 2018, Red joined the blockchain revolution—through an Initial Coin Offering (ICO) with its own cryptocurrency, RED (Red Community Token) token, and it gained a vast amount of new funding capital to sustain and accelerate its completion. Using its unique capabilities, a special dialect of Red called Red/C3 is being built, specifically dedicated to blockchain and smart contracts programming.

Since spring 2018, the Red project has been managed by the Red Foundation, based in Paris (France), and also led by Nenad Rakocevic. This organization will also foster a new economic model for open source projects, using the RED token to drive development.

What makes Red special?

Here we concentrate on the characteristics that sets Red apart from other contemporary programming languages.

A full-stack language – from the metal to the meta

Together with its foundation Red/System, Red forms a full-stack language—this means it can be used to develop high-level applications (domain-specific languages, graphical frontends, and high-level scripting) as well as low-level programs (embedded systems, operating systems, and device drivers), as shown in the following diagram in comparison with other languages:

It is quite unique in programming history that a single language spans the whole programming stack. This means that you as a Red developer only have to know one language from low to high level coding!

Code is data and data is code

Red is a modern descendant of the venerable LISP programming language. Instead of LISP's cumbersome parenthesis usage, it has taken Logo's simplified syntax. Everything in LISP is some kind of LISt Processing, and the same goes for Red—basically all code amounts to a combination of actions on blocks, which is the Red equivalent to LISP lists.

A block is simply a grouping of values between rectangular brackets [ ], such as [7 13 42]. You'll soon see that blocks are the fundamental building unit in Red code. This has the consequence that only a minimal syntax is used to represent code as well as data.

It will become clear that [ ] are used a lot in Red. On English or US keyboards this is easy, with its dedicated keys for [ and ]. On my (Dutch) keyboard it is ALTGR + ^ and ALTGR + $. On some keyboards, it is Alt + 5 and Alt + 6. I find it easier to switch to US keyboard layout while coding.

Like LISP, it has a very powerful capacity—it is homoiconic, literally self-representing. What this means is that Red can work with its code just as it does with its data values, because data and code are represented the same way, namely as blocks. This makes it possible for programs to write other programs, in other words, to do metaprogramming. We'll see several examples of this feature in the coming chapters.

Data types built in

For you as a developer to work with data efficiently, Red has more than 45 and counting built-in data types, from common types such as integers, chars, and strings to less common ones, such as pairs, tuples, files, URLs, emails, and so on. Moreover, you use the same set of operations to work with them, which greatly eases the learning curve. To do that in other languages, you would have to create objects from specialized classes to start working with them, or even import a library. As a first example, you can add and subtract days from a date value simply as follows:

;-- see Chapter01/special.red:
1-Feb-2018 + 14 ; == 15-Feb-2018
1-Feb-2018 – 42 ; == 21-Dec-2017

Small toolchain and executables

As we will see in the next chapter, when we're setting up, the complete toolchain (compilers, standard-library, docs, and REPL) comes packaged in a minimal 1 MB file, with no installation and configuration requirements—here we can see the reduction at work! Compare this with a Java runtime, which is about 150x bigger, or the Python runtime which also is 50 times bigger.

After compilation, Red produces executables of sizes typically around 0.5 to 1 MB, with no dependencies needed. This simplifies deployment of apps into production enormously. This aspect, combined with the low memory footprint, makes Red a very appealing choice for mobile and embedded apps. A garbage collector, which will be integrated in one of the next releases, ensures that memory consumption stays low.

Coding in Red is very expressive and concise, reducing script size, in the range of KBs. This will become apparent in the coming chapters. Just as an example, to read a web page into a string page you do the following:

page: read http://www.red-lang.org

In 2013, the Redmonk website published an article (which you can view here: http://redmonk.com/dberkholz/2013/03/25/programming-languages-ranked-by-expressiveness/) examining the expressiveness of languages. The results were summarized in the following diagram:

On the vertical axis, the number of lines of code per commit are depicted. We see that REBOL (Red's direct parent) scores very low compared to mainstream languages, indicating that fewer lines are needed in coding comparable tasks.

Dialects

One of Red's greatest strengths is the ability to easily create domain-specific languages (DSLs) or dialects. These are small and optimized sub-languages designed for a specific task, such as parse for transforming text (see Chapter 8, Parsing Data), view and draw for composing graphical user interfaces (see Chapter 9, Composing Visual Interfaces), and Red/C3 for blockchain programming (see Chapter 10, Advanced Red).

Red's main features

As a programming language, Red embraces nearly all paradigms:

  • Imperative: Providing everything needed for controlling code execution and error-handling (see Chapter 4, Code Controlling Structures and Chapter 5, Working with Series and Blocks)
  • Functional: With functions as first class values (see Chapter 6, Using Functions and Objects)
  • Object-oriented: Complete with inheritance, but not class-based (see Chapter 6, Using Functions and Objects)
  • Concurrency: With async task support and an actor model (from v 0.9.0)
  • Symbolic: Being able to manipulate its own code as if it was plain data (all chapters)
  • Reactive: Included in the GUI (Graphical User Interface) system (see Chapter 9, Composing Visual Interfaces and Chapter 10, Advanced Red)

Aside from REBOL and LISP, Red has taken inspiration from the following:

  • Forth and Logo for its syntax
  • Lua, for its capabilities as an embedded language, and its JIT (Just-In-Time) compiler
  • Self, for its prototype object-model
  • Scala, for its type inference engine and compilation

Although it can be statically compiled, Red has a graphical REPL console (Read Evaluate Print Loop) like other dynamic and scripting languages, to experiment with code interactively. We will explore this console in Chapter 2, Setting Up for Development.

In contrast to REBOL, which is an interpreted language only, Red also compiles to native code through Red/System, thus achieving much better performance, something like Crystal compared to Ruby. Compared to C, at this moment Red/System is 2-4x slower.

Portability

Red runs in the Windows, Linux, Android, macOS, and FreeBSD environments in a 32-bit version (the 64-bit version is planned) with cross-compilation capability. Furthermore, it runs on ARMv5 processors and on the Raspberry Pi and Arduino boards.

Like a Swiss Army knife

The versatility of the Red platform makes it suitable for apps on the entire spectrum, such as:

  • High-level scripting (for example, glue code such as Lua)
  • Web apps
  • GUI desktop applications
  • Android apps (from Version 0.7 onward)
  • 2D games
  • Data processing
  • Grammar parsing and constructing specialized languages
  • Network/system programming, IoT devices programming, robotics

Summary

In this chapter, we looked at Red's main characteristics, and examined its place among other programming languages. In the following chapter, we will set up an environment to start up our development with Red.

Questions

  1. Why does Red have a Red/System component?
  2. What is a full-stack language, and why is Red an example of that?
  3. What do the the Red and LISP languages have in common?
  4. Give three ways in which Red reduces software complexity.
  5. What is a dialect in Red? Give some examples.
  6. Why is Red faster than REBOL?
  7. Name some of the environments in which Red can run.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Explore the latest features of Red to build scalable, fast, and secure applications
  • • Learn graphical programming and build highly sophisticated reactive applications
  • • Get familiar with the specific concepts and techniques of Red development, like working with series, viewing code as data, and using dialects.

Description

A key problem of software development today is software bloat, where huge toolchains and development environments are needed in software coding and deployment. Red significantly reduces this bloat by offering a minimalist but complete toolchain. This is the first introductory book about it, and it will get you up and running with Red as quickly as possible. This book shows you how to write effective functions, reduce code redundancies, and improve code reuse. It will be helpful for new programmers who are starting out with Red to explore its wide and ever-growing package ecosystem and also for experienced developers who want to add Red to their skill set. The book presents the fundamentals of programming in Red and in-depth informative examples using a step-by-step approach. You will be taken through concepts and examples such as doing simple metaprogramming, functions, collections, GUI applications, and more. By the end of the book, you will be fully equipped to start your own projects in Red.

Who is this book for?

This book is for software developers and architects who want to learn Red because of its conciseness, flexibility, and expressiveness, and more specifically for its possibilities in GUI apps and blockchain / smart contracts programming. Some knowledge of the basic concepts and experience of any programming language is assumed.

What you will learn

  • • Set up your Red environment to achieve the highest productivity
  • • Get grounded in Red, gaining experience and insight through many examples and exercises
  • • Build simple, compact, and portable applications
  • • Analyze streams of data through Parse
  • • Compose GUI applications with View and Draw
  • • Get prepared for smart contract blockchain programming in Red

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 18, 2018
Length: 252 pages
Edition : 1st
Language : English
ISBN-13 : 9781789130706
Category :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : May 18, 2018
Length: 252 pages
Edition : 1st
Language : English
ISBN-13 : 9781789130706
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 116.97
Blockchain Quick Reference
$38.99
Blockchain for Enterprise
$38.99
Learn Red ? Fundamentals of Red
$38.99
Total $ 116.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Red's Mission Chevron down icon Chevron up icon
Setting Up for Development Chevron down icon Chevron up icon
Using Words, Values, and Types Chevron down icon Chevron up icon
Code-Controlling Structures Chevron down icon Chevron up icon
Working with Series and Blocks Chevron down icon Chevron up icon
Using Functions and Objects Chevron down icon Chevron up icon
Working with Files Chevron down icon Chevron up icon
Parsing Data Chevron down icon Chevron up icon
Composing Visual Interfaces Chevron down icon Chevron up icon
Advanced Red Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(2 Ratings)
5 star 50%
4 star 0%
3 star 50%
2 star 0%
1 star 0%
Gary A. Miller Aug 08, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book was critical for me in understanding and getting up and running with the Red programming language.The Red language is a different programming paradigm than most imperative, object oriented, or functional programming languages that most programmers are used to.This book helps you to understand and embrace this new paradigm and learn how powerful this language can really be!That being said this book has been out for three years and a great many things have added to Red.I would really encourage the author to come out with a second edition of the book now.
Amazon Verified review Amazon
Praveen Vaddadi Dec 23, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
A decent read. Mostly dwells on the "aftermath" of REBOL. True to its title, it talks about RED. However, it would have been useful had the author attempt led to connect RED to REBOL, instead of highlighting some features and omitting some others, risking an unnecessary rewrite of the ordinary aspects of the language.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.