From 5aa542280e58ddaabd84f75665702c25f11cc27d Mon Sep 17 00:00:00 2001 From: iArnold Date: Wed, 29 Jan 2014 16:14:56 +0100 Subject: Create red.html.markdown --- red.html.markdown | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 red.html.markdown diff --git a/red.html.markdown b/red.html.markdown new file mode 100644 index 00000000..cfe14c9b --- /dev/null +++ b/red.html.markdown @@ -0,0 +1,143 @@ +--- +name: Red +category: language +language: Red +filename: learnred.red +contributors: + - ["Arnold van Hofwegen", "https://github.com/iArnold"] +--- + + +Red was created out of the need to get work done, and the tool the author wanted to use, the language of REBOL, had a couple of drawbacks. +It was not Open Sourced at that time and it is an interpreted language, what means that it is on average slow compared to a compiled language. + +Red, together with its C-level dialect Red/System, provides a language that covers the entire programming space you ever need to program something in. +Red is a language heavily based on the language of REBOL. Where Red itself reproduces the flexibility of the REBOL language, the underlying language Red will be built upon, +Red/System, covers the more basic needs of programming like C can, being closer to the metal. + +Red will be the worlds first Full Stack Programming Language. This means that it will be an effective tool to do (almost) any programming task on every level +from the metal to the meta without the aid of other stack tools. +Furthermore Red will be able to cross-compile Red source code without using any GCC like toolchain +from any platform to any other platform. And it will do this all from a binary executable that is supposed to stay under 1 MB. + +Ready to learn your first Red? + +``` +Red + +; Single-line comments start with a semicolon ';' + +comment { + Multi-line comments + look like this. +} + +; Import files with #include and filenames start with a % sign +#include %includefile.red + +; Your program's entry point is the first executable code that is found +; no need to restrict this to a 'main' function. + +; Valid variable names start with a letter and can contain numbers, +; variables containing only capital A thru F and numbers and ending with 'h' are +; forbidden, because that is how hexadecimal numbers are expressed in Red and +; Red/System. + +; assign a value to a variable using a colon ':' +my-name: "Red" +reason-for-using-the-colon: {This makes the equality sign '=' exclusively usable for comparisons purposes, thus speeding up the original Rebol interpreter.} +is-this-name-valid?: true + +; print output using print, or prin for printing without a newline or linefeed at the ; end of the printed text. + +prin " My name is " print my-name +My name is Red + +print ["My name is " my-name lf] +My name is Red + +; In case you haven't already noticed: statements do NOT end with a semicolon ;-) + +; +; Datatypes +; +; If you know Rebol, you probably have noticed it has lots of datatypes. Red +; does not have yet all those types, but as Red want to be close to Rebol it +; will have a lot of datatypes. +; You can recognize types by the exclamation sign at the end. But beware +; names ending with an exclamation sign are allowed. +; Some of the available types are integer! string! block! + +; Declaring variables before using them? +; Red knows by itself what variable is best to use for the data you want to use it +; for. +; A variable declaration is not always necessary. +; It is considered good coding practise to declare your variables, +; but it is not forced upon you by Red. +; You can declare a variable and specify its type. a variable's type determines its +; size in bytes. + +; Variables of integer! type are usually 4 bytes or 32 bits +my-integer: 0 +; Red's integers are signed. No support for unsigned atm but that will come. + +; To find out the type of variable use type? +type? my-integer +integer! + +; chars are guaranteed to be 1 byte +; A string can be cast to a character +empty-string: "" +a-string: to-string #"a" + +i2: 1 + i1: 1 + +; Arithmetic is straightforward +i1 + i2 ; result 3 +i2 - i1 ; result 1 +i2 * i1 ; result 2 +i1 / i2 ; result 0 (0.5, but truncated towards 0) + +; Comparison operators are probably familiar, and unlike in other languages you +; only need a single '=' sign for comparison. +; There is a boolean like type in Red. It has values true and false, but also the +; values on/off or yes/no can be used + +3 = 2 ; => false +3 != 2 ; => true +3 > 2 ; => true +3 < 2 ; => false +2 <= 2 ; => true +2 >= 2 ; => true + +; +; Control Structures +; @TBD + +; +; Functions +; +; In Red almost everything can be seen as a function. Even the IF returns a value. + +; Function declaration syntax: +; function-name: function [][] +twice: function [a [integer!] /one return: [integer!]][ + c: 2 + a: a * c + either one [a + 1][a] +] + + + +``` + +## Further Reading + +The main source for information about Red is [the Red language homepage](http://www.red-lang.org). + +To learn more about Rebol and Red join the [chat on StackOverflow](http://chat.stackoverflow.com/rooms/291/rebol-and-red). +(You will need 20 points to chat but if you ask questions about Red or Rebol we will help you get those points). + +Maybe you want to try Red right away? That is possible on the [try Rebol and Red site](http://tryrebol.esperconsultancy.nl). + +You can also learn Red by learning [Rebol](http://www.rebol.com/docs.html). -- cgit v1.2.3 From d1376f0152f96073dd9ce754e3fac3ae2a89da69 Mon Sep 17 00:00:00 2001 From: iArnold Date: Wed, 29 Jan 2014 17:23:11 +0100 Subject: Update red.html.markdown --- red.html.markdown | 84 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index cfe14c9b..b0165693 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -22,19 +22,18 @@ from any platform to any other platform. And it will do this all from a binary e Ready to learn your first Red? -``` -Red +```Red + +;this is a commented line -; Single-line comments start with a semicolon ';' +print "hello world" ; this is another comment comment { - Multi-line comments - look like this. + This is a + multiline + comment } -; Import files with #include and filenames start with a % sign -#include %includefile.red - ; Your program's entry point is the first executable code that is found ; no need to restrict this to a 'main' function. @@ -85,10 +84,6 @@ my-integer: 0 type? my-integer integer! -; chars are guaranteed to be 1 byte -; A string can be cast to a character -empty-string: "" -a-string: to-string #"a" i2: 1 + i1: 1 @@ -112,7 +107,63 @@ i1 / i2 ; result 0 (0.5, but truncated towards 0) ; ; Control Structures -; @TBD +; +; if +; Execute a block of code if a given condition is true. IF does not return any value, +; so cannot be used in an expression. +if a < 0 [print "a is negative"] + +; either +; Execute a block of code if a given condition is true, else execute an alternative block of code. +; If last expressions in both blocks have the same type, EITHER can be used inside an expression. +either a < 0 [ + either a = 0 [ + msg: "zero" + ][ + msg: "negative" + ] +][ + msg: "positive" +] + +print ["a is " msg lf] + +; An alternative way to write it (allowed because all code paths return a value of the same type): + +msg: either a < 0 [ + either a = 0 [ + "zero" + ][ + "negative" + ] + ][ + "positive" +] +print ["a is " msg lf] + +; until +; Loop over a block of code until the condition at end of block, is met. UNTIL does not return any value, +; so cannot be used in an expression. +c: 5 +until [ + prin "o" + c: c - 1 + c = 0 +] +; will output: +ooooo +; Note that the loop will always be executed at least once, even if the condition is not met from the beginning. + +; while +; While a given condition is met, execute a block of code. WHILE does not return any value, +; so cannot be used in an expression. +c: 5 +while [c > 0][ + prin "o" + c: c - 1 +] +; will output: +ooooo ; ; Functions @@ -128,6 +179,9 @@ twice: function [a [integer!] /one return: [integer!]][ ] +; Import external files with #include and filenames start with a % sign +#include %includefile.red + ``` @@ -135,9 +189,11 @@ twice: function [a [integer!] /one return: [integer!]][ The main source for information about Red is [the Red language homepage](http://www.red-lang.org). +The Red/System language specification can be found [here](http://static.red-lang.org/red-system-specs-light.html). + To learn more about Rebol and Red join the [chat on StackOverflow](http://chat.stackoverflow.com/rooms/291/rebol-and-red). (You will need 20 points to chat but if you ask questions about Red or Rebol we will help you get those points). Maybe you want to try Red right away? That is possible on the [try Rebol and Red site](http://tryrebol.esperconsultancy.nl). -You can also learn Red by learning [Rebol](http://www.rebol.com/docs.html). +You can also learn Red by learning some [Rebol](http://www.rebol.com/docs.html). -- cgit v1.2.3 From 22ebe9a9b4d474341882aee8cbc82f63119e42e0 Mon Sep 17 00:00:00 2001 From: iArnold Date: Wed, 29 Jan 2014 21:27:53 +0100 Subject: Update red.html.markdown Equality sign means equal --- red.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index b0165693..f91b324b 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -42,9 +42,10 @@ comment { ; forbidden, because that is how hexadecimal numbers are expressed in Red and ; Red/System. -; assign a value to a variable using a colon ':' +; assign a value to a variable using a colon ":" my-name: "Red" -reason-for-using-the-colon: {This makes the equality sign '=' exclusively usable for comparisons purposes, thus speeding up the original Rebol interpreter.} +reason-for-using-the-colon: {Assigning values using the colon makes the equality sign "=" exclusively usable for comparisons purposes, exactly what "=" was intended for in the first place! Remember this y = x + 1 and x = 1 => y = 2 stuff from school? +} is-this-name-valid?: true ; print output using print, or prin for printing without a newline or linefeed at the ; end of the printed text. -- cgit v1.2.3 From 9a4a3c084fe34dcade067a6b3582d43b850757dc Mon Sep 17 00:00:00 2001 From: iArnold Date: Wed, 29 Jan 2014 21:30:53 +0100 Subject: Update red.html.markdown minor indentation --- red.html.markdown | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index f91b324b..ceaaf80f 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -44,11 +44,15 @@ comment { ; assign a value to a variable using a colon ":" my-name: "Red" -reason-for-using-the-colon: {Assigning values using the colon makes the equality sign "=" exclusively usable for comparisons purposes, exactly what "=" was intended for in the first place! Remember this y = x + 1 and x = 1 => y = 2 stuff from school? +reason-for-using-the-colon: {Assigning values using the colon makes + the equality sign "=" exclusively usable for comparisons purposes, + exactly what "=" was intended for in the first place! + Remember this y = x + 1 and x = 1 => y = 2 stuff from school? } is-this-name-valid?: true -; print output using print, or prin for printing without a newline or linefeed at the ; end of the printed text. +; print output using print, or prin for printing without a newline or linefeed at the +; end of the printed text. prin " My name is " print my-name My name is Red -- cgit v1.2.3 From ade0d072c00f68175dae50395e7d045e566c1a55 Mon Sep 17 00:00:00 2001 From: iArnold Date: Wed, 29 Jan 2014 21:35:28 +0100 Subject: Update red.html.markdown --- red.html.markdown | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index ceaaf80f..f277dd64 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -103,12 +103,12 @@ i1 / i2 ; result 0 (0.5, but truncated towards 0) ; There is a boolean like type in Red. It has values true and false, but also the ; values on/off or yes/no can be used -3 = 2 ; => false -3 != 2 ; => true -3 > 2 ; => true -3 < 2 ; => false -2 <= 2 ; => true -2 >= 2 ; => true +3 = 2 ; result false +3 != 2 ; result true +3 > 2 ; result true +3 < 2 ; result false +2 <= 2 ; result true +2 >= 2 ; result true ; ; Control Structures @@ -153,7 +153,7 @@ c: 5 until [ prin "o" c: c - 1 - c = 0 + c = 0 ; the condition to end the until loop ] ; will output: ooooo @@ -173,10 +173,7 @@ ooooo ; ; Functions ; -; In Red almost everything can be seen as a function. Even the IF returns a value. - -; Function declaration syntax: -; function-name: function [][] +; function example twice: function [a [integer!] /one return: [integer!]][ c: 2 a: a * c -- cgit v1.2.3 From 2793e0bd48afdf809923ac0bf461fb4153f120ad Mon Sep 17 00:00:00 2001 From: iArnold Date: Thu, 30 Jan 2014 09:32:58 +0100 Subject: Update red.html.markdown Added header info and completed Hello World program with the header. --- red.html.markdown | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index f277dd64..6e31eee9 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -23,15 +23,22 @@ from any platform to any other platform. And it will do this all from a binary e Ready to learn your first Red? ```Red +All text before the Red header will be treated as comment +The Red header is the word "Red" followed by a whitespace character followed by a block of square brackets []. +The block of brackets can be filled in with useful information about the script or program, the author, the version, the license, what the program does or needs. +The Red/System header is just like the Red header, only saying "Red/System" and not "Red". + +Red [] ;this is a commented line -print "hello world" ; this is another comment +print "Hello Red World" ; this is another comment comment { This is a multiline - comment + comment. + You just saw the Red version of the "Hello World" program. } ; Your program's entry point is the first executable code that is found -- cgit v1.2.3 From 026dcf7b2f9a5a3159d9d35c0da82b6180034e45 Mon Sep 17 00:00:00 2001 From: iArnold Date: Thu, 30 Jan 2014 09:57:20 +0100 Subject: Update red.html.markdown minor edits --- red.html.markdown | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index 6e31eee9..43fe03a6 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -23,9 +23,10 @@ from any platform to any other platform. And it will do this all from a binary e Ready to learn your first Red? ```Red -All text before the Red header will be treated as comment +All text before the Red header will be treated as comment. The Red header is the word "Red" followed by a whitespace character followed by a block of square brackets []. -The block of brackets can be filled in with useful information about the script or program, the author, the version, the license, what the program does or needs. +The block of brackets can be filled in with useful information about the script or program, the author, +the filename, the version, the license, what the program does or needs. The Red/System header is just like the Red header, only saying "Red/System" and not "Red". Red [] @@ -35,9 +36,7 @@ Red [] print "Hello Red World" ; this is another comment comment { - This is a - multiline - comment. + This is a multiline comment. You just saw the Red version of the "Hello World" program. } -- cgit v1.2.3 From c285bf758365107af78ce9a99c7f0d1e1f52421f Mon Sep 17 00:00:00 2001 From: iArnold Date: Thu, 30 Jan 2014 10:33:19 +0100 Subject: Update red.html.markdown completed function twice example --- red.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index 43fe03a6..55251e4e 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -185,17 +185,18 @@ twice: function [a [integer!] /one return: [integer!]][ a: a * c either one [a + 1][a] ] - +b: 3 +print twice b ; will output 6. ; Import external files with #include and filenames start with a % sign #include %includefile.red - +; Now the functions in the included file can be used too. ``` ## Further Reading -The main source for information about Red is [the Red language homepage](http://www.red-lang.org). +The main source for information about Red is the [Red language homepage](http://www.red-lang.org). The Red/System language specification can be found [here](http://static.red-lang.org/red-system-specs-light.html). -- cgit v1.2.3 From 28db2323b7e160de651cd4f62ef9b5cea089ae7f Mon Sep 17 00:00:00 2001 From: iArnold Date: Thu, 30 Jan 2014 11:05:00 +0100 Subject: Update red.html.markdown added giuthub source link and mailinglist --- red.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index 55251e4e..8060536d 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -198,10 +198,11 @@ print twice b ; will output 6. The main source for information about Red is the [Red language homepage](http://www.red-lang.org). +The source can be found on [github](https://github.com/red/red). + The Red/System language specification can be found [here](http://static.red-lang.org/red-system-specs-light.html). -To learn more about Rebol and Red join the [chat on StackOverflow](http://chat.stackoverflow.com/rooms/291/rebol-and-red). -(You will need 20 points to chat but if you ask questions about Red or Rebol we will help you get those points). +To learn more about Rebol and Red join the [chat on StackOverflow](http://chat.stackoverflow.com/rooms/291/rebol-and-red). You will need 20 points to chat but if you ask or answer questions about Red or Rebol we will help you get those points. And if that is not working for you drop a mail to us on the [Red mailing list](mailto: red-langNO_SPAM@googlegroups.com) (remove NO_SPAM). Maybe you want to try Red right away? That is possible on the [try Rebol and Red site](http://tryrebol.esperconsultancy.nl). -- cgit v1.2.3 From f1894bdd004cb1d19873da4f67eae6f314b1263a Mon Sep 17 00:00:00 2001 From: iArnold Date: Thu, 30 Jan 2014 20:47:29 +0100 Subject: Update red.html.markdown Avoid "Red" in the pre-header text --- red.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index 8060536d..ffcead51 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -23,11 +23,11 @@ from any platform to any other platform. And it will do this all from a binary e Ready to learn your first Red? ```Red -All text before the Red header will be treated as comment. -The Red header is the word "Red" followed by a whitespace character followed by a block of square brackets []. -The block of brackets can be filled in with useful information about the script or program, the author, +All text before the header will be treated as comment, as long as you avoid using the word "red" starting with a capital "R" in this pre-header text. Most of the time you start your script with the header itself. +The header of a redscript is the capitalized word "red" followed by a whitespace character followed by a block of square brackets []. +The block of brackets can be filled with useful information about the script or program, the author, the filename, the version, the license, what the program does or needs. -The Red/System header is just like the Red header, only saying "Red/System" and not "Red". +The red/System header is just like the red header, only saying "red/System" and not "red". Red [] -- cgit v1.2.3 From 471f67379ca4fc7ff421fc6de8824be30f35feeb Mon Sep 17 00:00:00 2001 From: iArnold Date: Thu, 30 Jan 2014 20:49:42 +0100 Subject: Update red.html.markdown --- red.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index ffcead51..c2e81b71 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -23,8 +23,10 @@ from any platform to any other platform. And it will do this all from a binary e Ready to learn your first Red? ```Red -All text before the header will be treated as comment, as long as you avoid using the word "red" starting with a capital "R" in this pre-header text. Most of the time you start your script with the header itself. -The header of a redscript is the capitalized word "red" followed by a whitespace character followed by a block of square brackets []. +All text before the header will be treated as comment, as long as you avoid using the word "red" +starting with a capital "R" in this pre-header text. Most of the time you start your script with +the header itself. The header of a redscript is the capitalized word "red" followed by a +whitespace character followed by a block of square brackets []. The block of brackets can be filled with useful information about the script or program, the author, the filename, the version, the license, what the program does or needs. The red/System header is just like the red header, only saying "red/System" and not "red". -- cgit v1.2.3 From 453341b5271e4136dcebe06dacde8361bfdee676 Mon Sep 17 00:00:00 2001 From: iArnold Date: Fri, 31 Jan 2014 13:55:24 +0100 Subject: Update red.html.markdown Corrections with editors glasses on. --- red.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index c2e81b71..73fe4bb0 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -15,7 +15,7 @@ Red, together with its C-level dialect Red/System, provides a language that cove Red is a language heavily based on the language of REBOL. Where Red itself reproduces the flexibility of the REBOL language, the underlying language Red will be built upon, Red/System, covers the more basic needs of programming like C can, being closer to the metal. -Red will be the worlds first Full Stack Programming Language. This means that it will be an effective tool to do (almost) any programming task on every level +Red will be the world's first Full Stack Programming Language. This means that it will be an effective tool to do (almost) any programming task on every level from the metal to the meta without the aid of other stack tools. Furthermore Red will be able to cross-compile Red source code without using any GCC like toolchain from any platform to any other platform. And it will do this all from a binary executable that is supposed to stay under 1 MB. @@ -24,10 +24,10 @@ Ready to learn your first Red? ```Red All text before the header will be treated as comment, as long as you avoid using the word "red" -starting with a capital "R" in this pre-header text. Most of the time you start your script with -the header itself. The header of a redscript is the capitalized word "red" followed by a +starting with a capital "R" in this pre-header text. Most of the time you start your script or program with +the header itself. The header of a red script is the capitalized word "red" followed by a whitespace character followed by a block of square brackets []. -The block of brackets can be filled with useful information about the script or program, the author, +The block of brackets can be filled with useful information about the script or program: the author, the filename, the version, the license, what the program does or needs. The red/System header is just like the red header, only saying "red/System" and not "red". @@ -97,7 +97,7 @@ my-integer: 0 type? my-integer integer! - +; A variable can be initialized using another variable that gets initialized at the same time. i2: 1 + i1: 1 ; Arithmetic is straightforward -- cgit v1.2.3 From 57b0ac6412cec6bcd1dfa50acbfe08805cf9ad95 Mon Sep 17 00:00:00 2001 From: iArnold Date: Fri, 31 Jan 2014 20:44:43 +0100 Subject: Update red.html.markdown Updated document on two things the author of Red pointed out. --- red.html.markdown | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index 73fe4bb0..9206f650 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -24,8 +24,9 @@ Ready to learn your first Red? ```Red All text before the header will be treated as comment, as long as you avoid using the word "red" -starting with a capital "R" in this pre-header text. Most of the time you start your script or program with -the header itself. The header of a red script is the capitalized word "red" followed by a +starting with a capital "R" in this pre-header text. This is a temporary shortcoming of the used lexer but +most of the time you start your script or program with the header itself. +The header of a red script is the capitalized word "red" followed by a whitespace character followed by a block of square brackets []. The block of brackets can be filled with useful information about the script or program: the author, the filename, the version, the license, what the program does or needs. @@ -122,12 +123,12 @@ i1 / i2 ; result 0 (0.5, but truncated towards 0) ; Control Structures ; ; if -; Execute a block of code if a given condition is true. IF does not return any value, +; Evaluate a block of code if a given condition is true. IF does not return any value, ; so cannot be used in an expression. if a < 0 [print "a is negative"] ; either -; Execute a block of code if a given condition is true, else execute an alternative block of code. +; Evaluate a block of code if a given condition is true, else evaluate an alternative block of code. ; If last expressions in both blocks have the same type, EITHER can be used inside an expression. either a < 0 [ either a = 0 [ @@ -165,10 +166,10 @@ until [ ] ; will output: ooooo -; Note that the loop will always be executed at least once, even if the condition is not met from the beginning. +; Note that the loop will always be evaluated at least once, even if the condition is not met from the beginning. ; while -; While a given condition is met, execute a block of code. WHILE does not return any value, +; While a given condition is met, evaluate a block of code. WHILE does not return any value, ; so cannot be used in an expression. c: 5 while [c > 0][ -- cgit v1.2.3