Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,23 @@ peek(n) {
### Variable Declaration

```ebnf
VarStmt = "nyan" identifier [ TypeExpr ] "=" Expr newline .
VarStmt = "nyan" identifier [ TypeExpr ] "=" Expr newline
| identifier "=" Expr newline .
```

Declares a variable and binds it to a value.
Declares a variable and binds it to a value. The `nyan` keyword may be left
out when the name has no type annotation, so `x = 42` declares `x` just as
`nyan x = 42` does.

```meow
nyan x int = 42
nyan name = "Nyantyu"
count = 3
```

A binding cannot be rebound. Writing `x = ...` for a name already bound in the
same scope or an enclosing one is a compile error, not a reassignment.

A binding written at the top level of the program belongs to the whole program,
so a function can read it even when the function is written above it. Its value
exists only once its line has run, though, and a function called before then
Expand All @@ -487,14 +494,6 @@ That failure is a Furball like any other, so `~>` can catch it. A name that is
bound nowhere at all is refused before the program runs, as an undefined
variable.

### Reassignment

```ebnf
AssignStmt = identifier "=" Expr newline .
```

Rebinds an existing variable to a new value.

### Function Declaration
Comment thread
135yshr marked this conversation as resolved.

```ebnf
Expand Down
19 changes: 9 additions & 10 deletions website/content/doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,23 @@ peek(n) {
### Variable Declaration

```ebnf
VarStmt = "nyan" identifier [ TypeExpr ] "=" Expr newline .
VarStmt = "nyan" identifier [ TypeExpr ] "=" Expr newline
| identifier "=" Expr newline .
```

Declares a variable and binds it to a value.
Declares a variable and binds it to a value. The `nyan` keyword may be left
out when the name has no type annotation, so `x = 42` declares `x` just as
`nyan x = 42` does.

```meow
nyan x int = 42
nyan name = "Nyantyu"
count = 3
```

A binding cannot be rebound. Writing `x = ...` for a name already bound in the
same scope or an enclosing one is a compile error, not a reassignment.

A binding written at the top level of the program belongs to the whole program,
so a function can read it even when the function is written above it. Its value
exists only once its line has run, though, and a function called before then
Expand All @@ -491,14 +498,6 @@ That failure is a Furball like any other, so `~>` can catch it. A name that is
bound nowhere at all is refused before the program runs, as an undefined
variable.

### Reassignment

```ebnf
AssignStmt = identifier "=" Expr newline .
```

Rebinds an existing variable to a new value.

### Function Declaration

```ebnf
Expand Down
Loading