text stringlengths 0 897 |
|---|
{chapterHead: "Day 1: First Steps", startingPageNum:7} |
{width: "50%"} |
 |
Q> Whether you want to uncover the secrets of the universe, or you just want to pursue a career in the 21st century, basic computer programming is an essential skill to learn. |
Q>— Stephen Hawking (theoretical physicist) |
A> **Chapter Objectives** |
A> - Learn how to run MiniScript code on the web. |
A> - Use the `print` command to make MiniScript display something on the screen. |
A> - Learn about numbers and strings. |
There are many ways to run MiniScript. You may even find MiniScript within some commercial or open-source game or software tool. But in this book we are going to cover just three. The last of these will be Mini Micro, of which you got a glimpse in the Introduction. In the middle will be command-line MiniScript. Bu... |
The home of MiniScript on the web is <https://miniscript.org/>, and you will find all sorts of useful resources there. Today, follow the "Try-It!" link, or just go directly to: |
_ |
: <https://miniscript.org/tryit/> |
This should bring up a page that looks something like the figure below. |
 |
The standard layout has a code editor (with a white background) on the left, and an input/output area (with a black background) on the right. If you find that they are instead stacked vertically, try stretching out your browser window until they appear side-by-side. This should work equally well on Mac, Windows, and ... |
{i: "code editor, Try-It!"} |
[code editor] |
: a text editor specialized for writing program code |
Down below the editor and input/output area, you'll find a "Help & Information" area that is chock full of useful stuff. By clicking on the items on the left, you can make explanations and reference material appear to the right. Many of the items on the left are folders; you can twist those open by clicking the littl... |
The code editor contains some sample MiniScript code to get you started. As it's only Day 1, this code probably doesn't make much sense to you yet. That's OK too. You'll understand everything there in a couple of weeks. |
For now, just select all the code in that code editor, and delete it. The code editor works just like any other text editor, word processor, or comment form you've ever used; the main difference is that it will automatically color your text as you type. Don't worry about what the colors mean for now; they're mostly t... |
Now it's time to write your very first MiniScript program -- and for many readers, your first program of any sort. We'll begin with the classic greeting program. After clearing out the sample code, type this into the code editor on the Try-It! page: |
{caption: "Greetings program"} |
```miniscript |
print "Hello world!" |
``` |
Type it exactly as shown here. Notice that `print` is all lowercase; that's important. Like most computer languages, MiniScript is *case-sensitive*, which means that if you get the capitalization wrong, it will not work. |
case-sensitive |
: a language or system where upper- and lower-case letters are considered different |
case-insensitive |
: a language or system where upper- and lower-case letters are considered the same |
After entering the above code, click the **Run Script** button. You should see the words "Hello world!" appear in green text in the input-output area. If you do, congratulations! You just wrote your first program! |
If you *don't* see that, then you probably have a typo. Congratulations to you as well, as you have discovered what happens when you make a mistake! Go back and check your work carefully -- spelling and punctuation must match exactly. |
D> Computers work fast, but they are very picky about the details. |
If you weren't so fortunate as to make a mistake on your first attempt, then please do so now. It's important not to be afraid of making a mistake. It is impossible to hurt the computer by anything you type on the Try-It! page. When the computer can't understand what you want, it never gets upset or impatient. It j... |
{caption: "Incorrect greetings program"} |
```miniscript |
Print "Hello world!" |
``` |
Can you spot the difference between this program and the first one? We've used a capital "P" here. Go ahead and enter this code, then click that **Run Script** button again! You will get no output in the input/output area, and instead, an error message will appear below, along the lines of: |
```terminal |
Runtime Error: Undefined Identifier: 'Print' is unknown in this context [line 1] |
``` |
This is MiniScript's way of telling you that it doesn't know what `Print` means -- even though it *does* know what `print` means, these are considered completely different words, because (again) MiniScript is case-sensitive. |
{i: "error, runtime"} |
Runtime Error |
: an error that occurs after the program starts running |
{i: "error, compiler"} |
Compiler Error |
: an error that happens even before the program starts running, when MiniScript is studying the code |
{i: "error, undefined identifier"} |
Undefined Identifier |
: a type of runtime error that occurs when you use a word MiniScript does not know |
Now you may be wondering, what about the words `Hello` and `world`? Are these words that MiniScript knows? The answer is no, and it doesn't need to, because we have enclosed them inside of quotation marks. This is something like giving an actor lines in a language he doesn't speak. A skillful actor can parrot the w... |
On the other hand, words that tell the computer to *do* something -- like `print` -- must *not* be in quotation marks, and they must be among the words the computer already knows. Today, `print` is the only such word you're going to learn, but starting tomorrow you'll learn more, and by the end of the book you'll know... |
A pair of quotation marks surrounding some words is called a *string*. This is because the characters (letters, numbers, etc.) are strung together in a certain order, like beads on a string. |
{i:"data type, string"} |
string |
: some letters, numbers, or punctuation surrounded by quotation marks |
The string in our program above was "Hello world!" But it can be anything. Try these: |
{caption: "More greetings"} |
```miniscript |
print "Greetings, program!" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.