text stringlengths 0 897 |
|---|
{width:"75%"} |
 |
Note that double-clicking the executable is not the only way to launch it; you can also open a Terminal window yourself, use `cd` to navigate to the folder containing MiniScript, and then enter `./MiniScript` to run it. This does essentially the same thing. |
### Linux |
If you're a Linux user, chances are extremely high that you don't need me telling you how to use the command line — you probably know more about it than I do! Just download the gzipped Linux binary from <https://miniscript.org/cmdline/>, unpack it, and put it somewhere in your search path. Then invoke it by name, lik... |
Some Linux users prefer to build their software from the source code. If that describes you, you can find a link on the MiniScript home page to the source code repository. The build process is pretty straightforward, and explained in the README file in the MiniScript-cpp directory. |
### Trouble-Shooting |
For many readers, this will be the first time you have ever tried to install and run a command-line program. With all the variations on operating systems out there, and these systems' (quite justified) concern for security, doing this can be tricky, and it's possible something has gone wrong. But this is an important... |
You may have someone in your home or office who has more experience with this sort of thing; show them what you're trying to do, and they may be able to help. Or, failing that, come to the MiniScript forums or Discord server (both reachable via <https://miniscript.org/>). We'll work together to get you unstuck. Comm... |
## The Read-Eval-Print Loop |
{i:"prompt"} |
Once you've got MiniScript running, you should be looking at a blinky cursor next to a ">" prompt. Now what? ...Now the fun begins! |
{i:"REPL, defined"} |
That prompt and cursor represent something called a read-eval-print loop, or REPL for short. That's a fancy way of saying that you can type and run code here interactively, as MiniScript itself will |
- **Read** input from the user, |
- **Evaluate** the expression or command entered, |
- **Print** the results, and |
- repeat (i.e. **Loop**) until told to quit. |
Try it! At the prompt, type |
```terminal |
> 6*7 |
``` |
and press Return or Enter. (Note that when examples are shown with a faint REPL prompt, like the `>` above, you don't type that; only type what comes after.) MiniScript immediately responds with |
```repl |
42 |
``` |
and then displays the ">" prompt again, waiting for your next command. That `6*7` you typed in was MiniScript code. You didn't need to use `print` here because that's a built-in function of the read-eval-print loop; it evaluated your MiniScript expression, `6*7`, and printed the result automatically. |
Prove that this is more than just a calculator by trying something a little more complex: |
```terminal |
> ceil(6*rnd) + ceil(6*rnd) |
``` |
This simulates rolling two dice. I can't say exactly what the output will be, except that it will be between 2 and 12, and most likely closer to 7! Here's your first power-user trick on the command line: *press the up-arrow key*, and the previous command should reappear on the prompt, with the cursor at the end. You... |
The command-line environment supports all the same MiniScript powers you know from the Try-It page, and then some. This includes variables, `print` and `input`, `wait`, loops, and so on. Carefully type in the following: |
```miniscript |
for i in range(10, 1) |
print i + "..." |
wait |
end for |
``` |
But hold on — something different happened after the "for" line, didn't it? The prompt changed from ">" to ">>>". This is the REPL's way of acknowledging that your input is not yet finished (because you have started a `for` loop, but not yet ended it). As you're typing this code, it actually looks like this: |
```terminal |
> for i in range(10, 1) |
>>> print i + "..." |
>>> wait |
>>> end for |
``` |
You may also notice that the statements inside the loop, `print` and `wait` in this example, don't do anything as soon as you type them. Only after you finish with the `end for` does the whole loop run and do whatever it does. |
Now, let's see what happens if things get out of control. Here's an infinite loop. Don't panic! |
```miniscript |
i = 0 |
while true |
i = i + 1 |
print i |
end while |
``` |
{i:"control-C"} |
Woo! MiniScript starts printing numbers very fast, with no sign of stopping. Fortunately *you* are the programmer; you are in charge! Hold the Control key down and then press the C key (i.e., the key combination called control-C). MiniScript stops and exits. This leaves you either at the command prompt, or (if you... |
It can sometimes happen that you make a mistake in entering some code in the REPL, and don't catch it until you've already pressed Return. There's no going back to edit something already entered; but you can often just replace a previous result with a new one (i.e., assign a new value to a variable if you made a mista... |
Obviously the REPL is not a great way to enter long programs. We'll be learning tomorrow how to use command-line MiniScript with programs stored in text files, which is better for writing more than a few lines of code. What's great about a REPL is that it is a very fast, very *interactive* way of experimenting with c... |
So, for the rest of this chapter, let's work exclusively in the REPL, while we learn about lists. |
## Lists |
You know that there are several different types of data in MiniScript. So far, we've talked about numbers (e.g. 42) and strings (e.g. "Hello World"). It's time to introduce a third data type: lists. |
{i:"data type, list"} |
list |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.