Skip to content

Commit

Permalink
improved hello world recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Jul 5, 2023
1 parent 972d42e commit 5b06aaf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions courses/Recipes/Toys/Hello/Hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ println("Hello world, this is my first Rascal program");
As the command above, a piece of code is not _reusable_. To be able to use some code again and
again, the best way is to wrap it in a ((Declarations-Function)), and then call it:

```rascal-commands
```rascal-shell
import IO;
void hello() {
println("Hello world, this is my first Rascal program");
Expand All @@ -36,7 +36,7 @@ the Rascal systems prompts you with `>>>>>>>` to
indicate that more input is needed.

Don't get scared by
the `void (): void hello();` that you get back
the `void (): function(|prompt:///|(0,76,<1,0>,<3,1>))` that you get back
when typing in the hello function. The first
`void ()` part says the result is a function that takes
no arguments and
Expand Down Expand Up @@ -70,7 +70,7 @@ This module should be placed in `<project dir>/src/demo/basic/Hello.rsc`.

Using this `Hello` module is now simple:

```rascal
```rascal-shell
import demo::basic::Hello;
hello();
```
Expand All @@ -84,5 +84,12 @@ to invoke this `private` `hello()` function.

#### Benefits

* ((println)) is a simple function that renders a string to the output stream
* The ((Values-String)) constants you pass to ((println)) may contain entire string templates with automatic indentation

#### Pitfalls

* Don't forget to import the ((module:IO)) module.
```rascal-shell,errors
println("I think I forgot to import the IO module...")
```

0 comments on commit 5b06aaf

Please sign in to comment.