Skip to content

Commit

Permalink
Merge pull request #795 from nevalang/tutorial-fixes
Browse files Browse the repository at this point in the history
Tutorial fixes
  • Loading branch information
emil14 authored Dec 2, 2024
2 parents 094fcd0 + a3aedd5 commit 17893ce
Show file tree
Hide file tree
Showing 96 changed files with 597 additions and 496 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "--trace", "switch"]
"cwd": "${workspaceFolder}/e2e",
"args": ["run", "--trace", "tutorial/src"]
},
{
"name": "DEBUG CODEGEN",
Expand Down
6 changes: 3 additions & 3 deletions docs/book/program_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Module is usually a git-repo but not necessary. Module that isn't published in g

### Manifest File

The manifest defines the module's minimum supported language version and dependencies. Here's an example manifest with a dependency on the Nevalang compiler version `0.28.1` and a third-party module:
The manifest defines the module's minimum supported language version and dependencies. Here's an example manifest with a dependency on the Nevalang compiler version `0.28.2` and a third-party module:

```yaml
neva: 0.28.1
neva: 0.28.2
deps:
github.com/nevalang/x:
path: github.com/nevalang/x
Expand All @@ -51,7 +51,7 @@ The `deps` field is a map where each dependency has an alias. When adding depend
> WIP: CLI tool planned for CI/CD to verify module's backward compatibility

```yaml
neva: 0.28.1
neva: 0.28.2
deps:
github.com/nevalang/x@0-0-12:
path: github.com/nevalang/x
Expand Down
55 changes: 45 additions & 10 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ After installation is finished, you should be able to run the `neva` CLI from yo
neva version
```

It should emit something like `0.28.1`
It should emit something like `0.28.2`

### Hello, World!

Expand Down Expand Up @@ -254,7 +254,7 @@ This structure introduces two fundamental concepts in Nevalang: modules and pack
A module is a set of packages with a manifest file (`neva.yaml`). When we created our project with `neva new`, it generated a basic module with the following manifest file:

```yaml
neva: 0.28.1
neva: 0.28.2
```
This defines the Nevalang version for our project. As your project grows, you can include dependencies on third-party modules here.
Expand Down Expand Up @@ -560,10 +560,8 @@ pub def AddIntStrings(left string, right string) (res int, err error) {
---
:left -> parse_left
:right -> parse_right
[parse_left:err, parse_right:err] -> :err // fan-in with error propagation
parse:res -> :res
(parse_left:res + parse_right:res) -> :res
}
```

Expand All @@ -582,9 +580,10 @@ import {
def Main(start any) (stop any) {
add utils.AddIntStrings
println fmt.Println<any>
---
:start -> '21' -> [add:left, add:right] // fan-out
[add:res, add:err] -> println -> :stop
:start -> '21' -> [add:left, add:right] // chain + fan-out
[add:res, add:err] -> println -> :stop // fan-in + chain
}
```

Expand Down Expand Up @@ -626,12 +625,36 @@ Both operands must share the same type, and the operator must support that type.
Operands can be any senders e.g. ports, constants, even other binary expressions. Let's add one more utility component to our `src/utils/utils.neva`:

```neva
pub def TriangleArea(b int, h int) (res float) {
pub def TriangleArea(b int, h int) (res int) {
((:b * :h) / 2) -> :res
}
```

Here, `(:b * :h)` is a binary expression used as the left operand of another binary expression. The calculation proceeds once both `:b` and `:h` are ready.
Here, `(:b * :h)` is a binary expression used as the left operand of another binary expression. The calculation proceeds once both `:b` and `:h` are ready. We can test it by changing content in `src/main.neva`

```neva
import {
fmt
@:src/utils
}
def Main(start any) (stop any) {
area utils.TriangleArea
println fmt.Println<any>
---
:start -> [
10 -> area:b,
20 -> area:h
]
area -> println -> :stop
}
```

Outputs:

```neva
100
```

Nevalang supports these binary operators:

Expand Down Expand Up @@ -694,6 +717,12 @@ def Main(start any) (stop any) {
}
```

Outputs:

```
100
```

This example calculates a triangle's area (base=20, height=10), checks if it's larger than 50, and prints either "Big" or "Small" accordingly. While contrived, it demonstrates how the ternary operator can be used in more complex scenarios.

### Switch
Expand Down Expand Up @@ -790,7 +819,7 @@ While switch can route messages by comparing values to multiple cases, it also s

```neva
pub def ClassifyInt(data int) (neg any, pos any) {
:start -> (:data >= 0) -> switch {
(:data >= 0) -> switch {
true -> :pos
_ -> :neg
}
Expand Down Expand Up @@ -836,6 +865,11 @@ So far we've explored message routing through comparison with set of values and
Let's add one more component to `src/utils/utils.neva` and call it `CommentOnUser`. If user's name "Bob" it will comment on that, because that's the most important thing, otherwise if user's age is under 18, it will comment about that. Otherwise, if there's nothing to comment, it will just panic.

```neva
import {
fmt
strconv
}
// ...existing code...
pub def CommentOnUser(name string, age int) (sig any) {
Expand All @@ -848,6 +882,7 @@ pub def CommentOnUser(name string, age int) (sig any) {
(:age < 18) -> 'Young fellow!' -> println2
_ -> panic
}
[println1, println2] -> :sig
}
```

Expand Down
2 changes: 1 addition & 1 deletion e2e/99_bottles_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/add_nums_from_stdin_naive/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/add_nums_from_stdin_with_default_any/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/add_nums_from_stdin_with_err_handling/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/add_nums_from_stdin_with_multuple_senders/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/add_nums_from_stdin_with_sub_components/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/add_nums_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/array_inport_holes/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/array_outport_holes/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/add_floats/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/add_ints/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/add_strings/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/divide_floats/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/divide_ints/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/modulo/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/multiply_floats/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/multiply_ints/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/power/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/subtract_floats/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/arithmetic/subtract_ints/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/bitwise/and/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/bitwise/left_shift/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/bitwise/or/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/bitwise/right_shift/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/bitwise/xor/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/comparison/equal/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/comparison/greater_int/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/comparison/less_int/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/comparison/less_or_equal_int/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/comparison/not_equal/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/logical/and/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/binary_operators/logical/or/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/cli_new/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/comments/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/compiler_error_unused_outport/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/const_refs_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/div_test/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/do_nothing_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/duplicate_receiver/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/duplicate_sender/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/echo_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/enums_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/float_const_with_int_lit/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/for_loop_over_list_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/for_with_range_and_if/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/hello_world_verbose/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
2 changes: 1 addition & 1 deletion e2e/hello_world_with_const_sender/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.28.1
neva: 0.28.2
Loading

0 comments on commit 17893ce

Please sign in to comment.