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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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

eBook
$20.98 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Learn Red ? Fundamentals of Red

Setting Up for Development

Now we are going to set the stage for our future Red development. We'll get Red on to your computer, and then immediately start working in the Red console to get a feel for the environment. Then, we'll create our first script, run it in the console, and then compile and execute it. We will also discuss how Red compiles and what the different compilation options are. Finally, we'll show some coding environments to craft your Red code with ease.

We will cover the following topics:

  • Installing Red
  • Working interactively in the Red console
  • Running and compiling your first script
  • Other compilation options
  • Red's compilation model
  • Development environments for writing Red

Technical requirements

Installing Red

To get Red on your machine, simply download and save the latest stable version that corresponds to your operating system (OS) from here: http://www.red-lang.org/p/download.html. The download is named red-num (on Windows, the file also has an .exe extension), where num is the version number, such as 063. This small file (around 1 MB) contains the full Red toolchain, runtime library, and console source code, truly batteries included! It is that small because no external dependencies other than the OS are included.

On the downloads page, you can also find the nightly automated build and the latest source code from the master branch. If you want to work with a Red version that has the latest functionalities, download the nightly master build. For regular development, you better stick with the last stable version.

Red's runtime library is written as a mix of Red...

Working interactively in the Red console

Like any dynamic language, Red has a REPL console. The red command without arguments (open or double-click red.bat) starts a graphical window console on Windows and macOS, and a command-line console on Linux. If you need a command-line console on Windows and macOS, just use the command red --cli.

The console is a full Red interpreter and expects the input of Red code after the >> prompt, to evaluate and then execute it when pressing Enter. It's a live interaction with the language. Simply giving it a value (here a string indicated by "") returns that value after the ==:

;-- see Chapter02/console-examples.red:
>> "Red is awesome"
== "Red is awesome"

(You can find the source code of these examples in ch2/console-examples.red. In all code files, we'll indicate the returned output with a ;=...

Running and compiling your first script

Experimenting in the REPL is fine for small code fragments and you should definitely use it, but soon you will want to keep your code in a file. Use your preferred code editor (or look at the last Development environments for writing Red section of this chapter for editors and IDEs with support for Red development) and type in the following text:

;-- see Chapter02/hello-world.red:
Red [
Title: "Simple hello world script"
]
print "Hello Red World!"

Save the file as hello-world.red; .red is the extension for Red source code files.

The Red [ ] header block is mandatory; we'll see its purpose in the next chapter.

Executing a script in the Red console

Using the Red...

Other compilation options

To see the documentation on the red command, type red –h in a Terminal. Here are some useful options:

  • Use –o to name the output binary differently.
  • Use –d in debugging mode. Functions used to print debug info (such as print and probe) show their output in the Red console.
  • Use –dlib to make a shared library from code, for example, for a code file containing only functions.
  • Use -e in combination with either -c or -r to compile in encapped mode; the runtime will be compiled and included in a single binary, together with your script. However, your script is not compiled; it is converted to a special format (Redbin) and compressed. The result is a standalone executable, and your script will be run by the interpreter. This can be useful when you encounter a compiler limitation, but your code can still be interpreted.

One of the...

Red's compilation model

From the previous screenshot of a red -r release-mode compilation, we see that this takes two steps:

  1. The first step doesn't state it explicitly, but it compiles the Red source code to Red/System code.
  1. The second one compiles Red/System to native code:

As mentioned, compilation is done with the REBOL red.r script. Due to this, Red is currently 32-bit only, self-hosting will make 64-bit binaries possible.

If you are feeling adventurous, you can experiment with compiling Red from within the REBOL console. Visit: https://github.com/red/red#running-red-from-the-sources-for-contributors

At this moment, there are two distinct modes of executing a Red program:

  • Running with the interpreter, which takes place in memory and involves some amount of compilation
  • Compiling to native code in a binary file and then running this executable, with Red/System...

Development environments for writing Red

You basically need no more than a simple text editor and a Terminal for compiling work. However, some syntax highlighting and perhaps a built-in compile and run system can make your life much easier.

Simple text editors

Summary

By now, you should have a running development environment and be able to work with the Red console. You have also learned how to compile and execute a simple script, in development mode as well as in release mode. You learned the most important compilation options, such as renaming the output file with -o, or cross-compiling your program to another deployment platform with -t. You also gained some insight into Red’s compilation model. Finally, we reviewed the existing editor options and prepared a comfortable environment to start coding, working interactively with the Red console as well as with source files.

In the following chapter, we'll explore the basic building blocks of a Red program—words, values, and their types.

Questions

  1. Use print to print out Hello Red world! then use prin. What's the difference? Look it up with ? Now use prn. What happens and why?
  2. What is the purpose of the red.r script?
  3. What is a self-hosting language?
  4. Which function must you use to execute a script from within the console?
  5. Do you need libRedRT in release mode?
  6. If not, then where is its code?
  7. Which Red development environment gives you code completion?

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
Estimated delivery fee Deliver to Chile

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Chile

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

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 $62.94 $89.97 $27.03 saved
Learn Red ? Fundamentals of Red
$38.99
Blockchain for Enterprise
$38.99
Blockchain Quick Reference
$38.99
Total $62.94$89.97 $27.03 saved Stars icon

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 the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela