From 4bb86b05e31ed9a780e18f59b22b2fc5652ee141 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 31 Oct 2022 07:45:43 -0400 Subject: [PATCH] Explain REPL auto-vars in tutorial --- www/public/site.css | 8 +++++++- www/public/tutorial/index.html | 30 +++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/www/public/site.css b/www/public/site.css index 5fb69b073d..008f7088d3 100644 --- a/www/public/site.css +++ b/www/public/site.css @@ -24,13 +24,19 @@ code.snippet, samp { white-space: pre; padding: 10px 16px; background-color: #eee; + margin-bottom: 16px; } -code .ann, samp .ann { +.ann { /* type annotation - purple in the repl */ color: rebeccapurple; } +.autovar { + /* automatic variable names in the repl, e.g. # val1 */ + color: green; +} + /* Used on on the different-names page. */ th, td { diff --git a/www/public/tutorial/index.html b/www/public/tutorial/index.html index e2d8598314..cdfb56ca92 100644 --- a/www/public/tutorial/index.html +++ b/www/public/tutorial/index.html @@ -42,16 +42,32 @@ short.

The rockin’ roc repl

So far, so good!

Hello, World!

-

Try typing this at the REPL prompt and pressing enter:

+

Try typing this at the REPL prompt and pressing Enter:

"Hello, World!"

The REPL should cheerfully display the following:

-"Hello, World!" : Str +"Hello, World!" : Str # val1

Congratulations! You've just written your first Roc code!

-

Arithmetic

-

When you entered the expression "Hello, World!" into the REPL, +

String Interpolation

+

When you entered the expression "Hello, World!", the REPL printed it back out. It also printed : Str, because -Str is the expression's type. We'll talk about types later; for now, let's ignore -the : and whatever comes after it whenever the REPL prints them.

+Str is that expression's type. We'll talk about types later; for now, let's ignore +the : and whatever comes after it whenever we see them.

+

The REPL also printed # val1 at the end of the line. +That means from now on you can use the variable name val1 to refer +to the "Hello, World!" expression you just entered. This comes in handy +when entering complicated expressions! Future sections of the tutorial will omit these labels, since they're +just there as a convenience.

+

Still, while we're talking about them, let's try it out. Put this into the repl and press Enter:

+val1 +

You should see the same "Hello, World!" line as before.

+

You can also create your own names for expressions. Try entering these lines:

+greeting = "Hi" +audience = "World" +"\(greeting), \(audience)!" +

After entering that last one, you should see this output:

+"Hi, World!" : Str # val2 +

This

+

Arithmetic

Next let's try putting in a more complicated expression:

1 + 1 @@ -64,7 +80,7 @@ be grouped.

-1 : Num *

Functions

-

Let's try calling a function:

+

Let's try calling a function:

>> Str.concat "Hi " "there!"
 "Hi there!" : Str