mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Update red.html.markdown
Some of the code lines were too long to fit the box so I shortened these and made a few changes in the text so it looks better at the points where the extra lines were added.
This commit is contained in:
parent
8d82b55947
commit
bcd930047d
@ -23,14 +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 word "red"
|
All text before the header will be treated as comment, as long as you avoid using the
|
||||||
starting with a capital "R" in this pre-header text. This is a temporary shortcoming of the used lexer but
|
word "red" starting with a capital "R" in this pre-header text. This is a temporary
|
||||||
most of the time you start your script or program with the header itself.
|
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
|
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 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 this script or
|
||||||
the filename, the version, the license, what the program does or needs.
|
program: the author's name, the filename, the version, the license, a summary of
|
||||||
The red/System header is just like the red header, only saying "red/System" and not "red".
|
what the program does or any other files it needs.
|
||||||
|
The red/System header is just like the red header, only saying "red/System" and
|
||||||
|
not "red".
|
||||||
|
|
||||||
Red []
|
Red []
|
||||||
|
|
||||||
@ -98,7 +101,8 @@ my-integer: 0
|
|||||||
type? my-integer
|
type? my-integer
|
||||||
integer!
|
integer!
|
||||||
|
|
||||||
; A variable can be initialized using another variable that gets initialized at the same time.
|
; A variable can be initialized using another variable that gets initialized
|
||||||
|
; at the same time.
|
||||||
i2: 1 + i1: 1
|
i2: 1 + i1: 1
|
||||||
|
|
||||||
; Arithmetic is straightforward
|
; Arithmetic is straightforward
|
||||||
@ -128,8 +132,9 @@ i1 / i2 ; result 0 (0.5, but truncated towards 0)
|
|||||||
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 block of code.
|
; Evaluate a block of code if a given condition is true, else evaluate an alternative
|
||||||
; If last expressions in both blocks have the same type, EITHER can be used inside an expression.
|
; block of code. If the last expressions in both blocks have the 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"
|
||||||
@ -142,7 +147,8 @@ either a < 0 [
|
|||||||
|
|
||||||
print ["a is " msg lf]
|
print ["a is " msg lf]
|
||||||
|
|
||||||
; An alternative way to write it (allowed because all code paths return a value of the same type):
|
; There is an alternative way to write this
|
||||||
|
; (Which is allowed because all code paths return a value of the same type):
|
||||||
|
|
||||||
msg: either a < 0 [
|
msg: either a < 0 [
|
||||||
either a = 0 [
|
either a = 0 [
|
||||||
@ -156,8 +162,8 @@ msg: either a < 0 [
|
|||||||
print ["a is " msg lf]
|
print ["a is " msg lf]
|
||||||
|
|
||||||
; until
|
; until
|
||||||
; Loop over a block of code until the condition at end of block, is met. UNTIL does not return any value,
|
; Loop over a block of code until the condition at end of block, is met.
|
||||||
; so cannot be used in an expression.
|
; UNTIL does not return any value, so it cannot be used in an expression.
|
||||||
c: 5
|
c: 5
|
||||||
until [
|
until [
|
||||||
prin "o"
|
prin "o"
|
||||||
@ -166,11 +172,12 @@ until [
|
|||||||
]
|
]
|
||||||
; will output:
|
; will output:
|
||||||
ooooo
|
ooooo
|
||||||
; Note that the loop will always be evaluated 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
|
||||||
; While a given condition is met, evaluate a block of code. WHILE does not return any value,
|
; While a given condition is met, evaluate a block of code.
|
||||||
; so cannot be used in an expression.
|
; WHILE does not return any value, so it cannot be used in an expression.
|
||||||
c: 5
|
c: 5
|
||||||
while [c > 0][
|
while [c > 0][
|
||||||
prin "o"
|
prin "o"
|
||||||
|
Loading…
Reference in New Issue
Block a user