Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
ion
Commits
9021a74e
Verified
Commit
9021a74e
authored
6 years ago
by
jD91mZM2
Browse files
Options
Downloads
Patches
Plain Diff
Manual: Mention behavior of scopes and functions
parent
b9a10798
No related branches found
No related tags found
2 merge requests
!801
Re-implement scopes
,
!798
Manual: Mention behavior of scopes and functions
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
manual/src/ch04-05-scopes.md
+23
-2
23 additions, 2 deletions
manual/src/ch04-05-scopes.md
with
23 additions
and
2 deletions
manual/src/ch04-05-scopes.md
+
23
−
2
View file @
9021a74e
...
@@ -23,6 +23,27 @@ if test 1 == 1
...
@@ -23,6 +23,27 @@ if test 1 == 1
# end of scope, y is deleted since it's owned by it
# end of scope, y is deleted since it's owned by it
end
end
echo "$x" # prints 2
echo $x # prints 2
echo "$y" # prints nothing, y is deleted already
echo $y # prints nothing, y is deleted already
```
## Functions
Functions have the scope they were defined in.
This ensures they don't use any unintended local variables that only work in some cases.
Once again, this matches the behavior of most other languages, apart from perhaps LOLCODE.
```
ion
let x = 5 # defines x
fn print_vars
echo $x # prints 2 because it was updated before the function was called
echo $y # prints nothing, y is owned by another scope
end
if test 1 == 1
let x = 2 # updates existing x
let y = 3 # defines y
print_vars
end
```
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment