Almost all of the programming tutorials start with a small example. The goal is to get the reader ready for the development environment and be familiar with the use of the compilation tools. We also follow the tradition, from this most basic step to start.
Unlike the first Hello World program in most programming languages, let's do something more interesting. The program demo.red as follows:
Red [ title: "Red Alpha simple ASCII Art demo" Author: "Nenad Rakocevic"   ; file: %demo.red tabs: 4 Rights: "Copyright (C) Nenad Rakocevic. All rights reserved. " License: { distributed under the
Boost Software License, Version 1.0.
Https://github.com/dockimbel/Red/blob/master/BSL-License.txt }] Data: [ [0 7] [2 2 6 7] [1 2 6 7 20 ] [0 2 6 7] [2 2 6 7] [9 1 7 9 0] [0 2 4 5 9] [2 2 5 6 (9)] [1 2 5 6 9] [0 2 6]] pattern: "Red" Prin newline
foreach line data [ cursor:1 + line/1 line:next line Gap-star T:LINE/1 gap-end:line/2 prin tab prin tab & nbsp; repeat I [ prin either all [ & nbsp; Gap-start <= i i <= gap-end [ # " [ Pattern/:cursor ] if i > gap-end [ unless tail? Line:skip Line 2 [ GAP-START:LINE/1 GAP-END:LINE/2 ] ] Cursor:cursor + 1 if cursor = 4 [cursor
: 1] ] prin newline]
The program is a bit long, but it doesn't matter, now we don't need to understand it, our goal is to learn how to run this code.
First, download the Red tool chain. Red appears to be too slim and even doubtful about the ability of hundreds of MB of tool chains compared to other programming languages. Can you imagine a tool less than 1MB, containing two compilers (red and Red/system), an interpreter (red)? It's though small, spite.
Official Download Address: Http://red.github.io
Next, take the Windows platform as an example:
1. Open cmd, explain execution:
E:\>red-051.exe demo.red redred D d d e e e R r r edr DR D d d d r R Re edredr e d d R r e redr e D d e d r e e r e d d DR & nbsp; r R edr DR D e:\>
2. Run after compiling. Explain the execution is convenient, the disadvantage is that the program is running speed, and need to have red interpreter to run the program. After compiling, a standalone executable file is generated that can make up for the defects mentioned earlier.
E:\>red-051.exe-c demo.red
-=== red Compiler 0.5.1 ===-
...
... compilation time:241 Ms compiling to
native code ...
... compilation time:13256 ms ...
linking time : 189 ms
... output file size:348672 bytes
... output file< c9/>: E:\demo.exe
e:\>demo.exe
redred d
d e e R
R r EdR DR d
D r r Re
edredr e d D r
R E redr e d
d E d r E
e r e D D DR
R R EdR DR D
3. Enter the REPL environment.
E:\>red-051.exe
-=== Red Console alpha version ===-
Type Help for starting information.
Red>> 1 + 2
= 3
red>> print "Hello"
hello
red>> quit
e:\>
Well, now that you've basically learned the use of the Red tool chain, it's as simple as that. :D
If you know more command-line arguments, you can do the following:
E:\>red-051.exe-h
Children's shoes can follow the help instructions to try to compile the DLL and cross-compile (compile Linux or Mac version of the program on Windows). In the next article, we will formally enter the red language learning.