Running code
Of course you may save your script as a file and run it from command prompt, as an argument of the Red executable, like this:
C:\Users\you\whatever> red-063.exe myprogram.red
This will launch the Red interpreter, open the console (REPL) and run your script.
But once the Red environment is running, you can execute code using the built-in function do .
native! do Red-by-example MyCode4fun
Evaluates the code in its arguments. In other words: executes the code. This argument can be a block, a file, a function or any other value.
>> do [loop 3 [print "hello"]]
hello
hello
hello
Check the Files chapter before you proceed here.
For example, if you saved a Red script as myprogram.txt you may execute it from the console by typing this:
>> do %myprogram.txt
Note that in this example the Red interpreter and the text file must be in the same folder, otherwise you must set your paths right.
Also, if you type:
>> a: load %myprogram.txt
And then:
>> do a
...your program will run normally.
do, load and save are better understood if you think of Red's console as the screen of some old computer from the 80's running some variation of basic language. You can load your program, save it, or do (execute) it.
You can also load and execute functions saved as text :
>> do load %myfunction.txt
Notice that you can do all this from inside a Red program! So it's a powerful command.