mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-26 20:34:32 +03:00
[red/en] changing the formatting of comments so that lines are always less than 80 characters.
This commit is contained in:
parent
e5416f2a34
commit
3e7394b796
@ -23,17 +23,17 @@ from any platform to any other platform. And it will do this all from a binary e
|
|||||||
Ready to learn your first Red?
|
Ready to learn your first Red?
|
||||||
|
|
||||||
```
|
```
|
||||||
All text before the header will be treated as comment, as long as you avoid using the
|
All text before the header will be treated as comment, as long as you avoid
|
||||||
word "red" starting with a capital "R" in this pre-header text. This is a temporary
|
using the word "red" starting with a capital "R" in this pre-header text.
|
||||||
shortcoming of the used lexer but most of the time you start your script or program
|
This is a temporary shortcoming of the used lexer but most of the time you
|
||||||
with the header itself.
|
start your script or program with the header itself.
|
||||||
|
|
||||||
The header of a red script is the capitalized word "red" followed by a
|
The header of a red script is the capitalized word "red" followed by a
|
||||||
whitespace character followed by a block of square brackets [].
|
whitespace character followed by a block of square brackets []. The block of
|
||||||
The block of brackets can be filled with useful information about this script or
|
brackets can be filled with useful information about this script or program:
|
||||||
program: the author's name, the filename, the version, the license, a summary of
|
the author's name, the filename, the version, the license, a summary of what
|
||||||
what the program does or any other files it needs.
|
the program does or any other files it needs. The red/System header is just
|
||||||
The red/System header is just like the red header, only saying "red/System" and
|
like the red header, only saying "red/System" and not "red".
|
||||||
not "red".
|
|
||||||
|
|
||||||
Red []
|
Red []
|
||||||
|
|
||||||
@ -50,9 +50,9 @@ comment {
|
|||||||
; no need to restrict this to a 'main' function.
|
; no need to restrict this to a 'main' function.
|
||||||
|
|
||||||
; Valid variable names start with a letter and can contain numbers,
|
; 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
|
; variables containing only capital A thru F and numbers and ending with 'h'
|
||||||
; forbidden, because that is how hexadecimal numbers are expressed in Red and
|
; are forbidden, because that is how hexadecimal numbers are expressed in Red
|
||||||
; Red/System.
|
; and Red/System.
|
||||||
|
|
||||||
; assign a value to a variable using a colon ":"
|
; assign a value to a variable using a colon ":"
|
||||||
my-name: "Red"
|
my-name: "Red"
|
||||||
@ -63,8 +63,8 @@ reason-for-using-the-colon: {Assigning values using the colon makes
|
|||||||
}
|
}
|
||||||
is-this-name-valid?: true
|
is-this-name-valid?: true
|
||||||
|
|
||||||
; print output using print, or prin for printing without a newline or linefeed at the
|
; print output using print, or prin for printing without a newline or linefeed
|
||||||
; end of the printed text.
|
; at the end of the printed text.
|
||||||
|
|
||||||
prin " My name is " print my-name
|
prin " My name is " print my-name
|
||||||
My name is Red
|
My name is Red
|
||||||
@ -72,7 +72,7 @@ My name is Red
|
|||||||
print ["My name is " my-name lf]
|
print ["My name is " my-name lf]
|
||||||
My name is Red
|
My name is Red
|
||||||
|
|
||||||
; In case you haven't already noticed: statements do NOT end with a semicolon ;-)
|
; If you haven't already noticed: statements do NOT end with a semicolon ;-)
|
||||||
|
|
||||||
;
|
;
|
||||||
; Datatypes
|
; Datatypes
|
||||||
@ -85,13 +85,13 @@ My name is Red
|
|||||||
; Some of the available types are integer! string! block!
|
; Some of the available types are integer! string! block!
|
||||||
|
|
||||||
; Declaring variables before using them?
|
; Declaring variables before using them?
|
||||||
; Red knows by itself what variable is best to use for the data you want to use it
|
; Red knows by itself what variable is best to use for the data you want to
|
||||||
; for.
|
; use it for.
|
||||||
; A variable declaration is not always necessary.
|
; A variable declaration is not always necessary.
|
||||||
; It is considered good coding practise to declare your variables,
|
; It is considered good coding practise to declare your variables,
|
||||||
; but it is not forced upon you by Red.
|
; but it is not forced upon you by Red.
|
||||||
; You can declare a variable and specify its type. a variable's type determines its
|
; You can declare a variable and specify its type. a variable's type
|
||||||
; size in bytes.
|
; determines its size in bytes.
|
||||||
|
|
||||||
; Variables of integer! type are usually 4 bytes or 32 bits
|
; Variables of integer! type are usually 4 bytes or 32 bits
|
||||||
my-integer: 0
|
my-integer: 0
|
||||||
@ -111,10 +111,10 @@ i2 - i1 ; result 1
|
|||||||
i2 * i1 ; result 2
|
i2 * i1 ; result 2
|
||||||
i1 / i2 ; result 0 (0.5, but truncated towards 0)
|
i1 / i2 ; result 0 (0.5, but truncated towards 0)
|
||||||
|
|
||||||
; Comparison operators are probably familiar, and unlike in other languages you
|
; Comparison operators are probably familiar, and unlike in other languages
|
||||||
; only need a single '=' sign for comparison.
|
; 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
|
; There is a boolean like type in Red. It has values true and false, but also
|
||||||
; values on/off or yes/no can be used
|
; the values on/off or yes/no can be used
|
||||||
|
|
||||||
3 = 2 ; result false
|
3 = 2 ; result false
|
||||||
3 != 2 ; result true
|
3 != 2 ; result true
|
||||||
@ -127,14 +127,14 @@ i1 / i2 ; result 0 (0.5, but truncated towards 0)
|
|||||||
; Control Structures
|
; Control Structures
|
||||||
;
|
;
|
||||||
; if
|
; if
|
||||||
; Evaluate 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
|
||||||
; so cannot be used in an expression.
|
; any value, so cannot be used in an expression.
|
||||||
if a < 0 [print "a is negative"]
|
if a < 0 [print "a is negative"]
|
||||||
|
|
||||||
; either
|
; either
|
||||||
; Evaluate a block of code if a given condition is true, else evaluate an alternative
|
; Evaluate a block of code if a given condition is true, else evaluate an
|
||||||
; block of code. If the last expressions in both blocks have the same type, EITHER can
|
; alternative block of code. If the last expressions in both blocks have the
|
||||||
; be used inside an expression.
|
; same type, EITHER can be used inside an expression.
|
||||||
either a < 0 [
|
either a < 0 [
|
||||||
either a = 0 [
|
either a = 0 [
|
||||||
msg: "zero"
|
msg: "zero"
|
||||||
@ -172,8 +172,8 @@ until [
|
|||||||
]
|
]
|
||||||
; will output:
|
; will output:
|
||||||
ooooo
|
ooooo
|
||||||
; Note that the loop will always be evaluated at least once, even if the condition is
|
; Note that the loop will always be evaluated at least once, even if the
|
||||||
; not met from the beginning.
|
; condition is not met from the beginning.
|
||||||
|
|
||||||
; while
|
; while
|
||||||
; While a given condition is met, evaluate a block of code.
|
; While a given condition is met, evaluate a block of code.
|
||||||
|
Loading…
Reference in New Issue
Block a user