Skip to content

Commit

Permalink
add FUNCNAME and FUNCNEST notes
Browse files Browse the repository at this point in the history
  • Loading branch information
glennj committed Jan 9, 2025
1 parent 5e22a8b commit f72a5cf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
32 changes: 32 additions & 0 deletions concepts/functions/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ Similarly, _assigning_ a value to a variable will assign it _in the scope where
This "action at a distance" can create hard-to-follow code, as it is not always obvious where a variable was assigned a value.
~~~~

~~~~exercism/advanced
The call stack can be examined using [the `FUNCNAME` array variable][funcname].
[funcname]: https://www.gnu.org/software/bash/manual/bash.html#index-FUNCNAME
~~~~

## Return Values

A function, like any command, has an _exit status_.
Expand Down Expand Up @@ -209,5 +215,31 @@ for i in {1..10}; do fibonacci "$i"; done
# => 89
```

~~~~exercism/advanced
The recursion depth can be controlled with [the `FUNCNEST` variable][funcnest].
```bash
bash -c '
recur() {
echo $1
recur $(($1 + 1))
}
FUNCNEST=5
recur 1
'
```
```none
1
2
3
4
5
environment: line 1: recur: maximum function nesting level exceeded (5)
```
[funcnest]: https://www.gnu.org/software/bash/manual/bash.html#index-FUNCNEST
~~~~

[variables]: https://exercism.org/tracks/bash/concepts/variables
[man-funcs]: https://www.gnu.org/software/bash/manual/bash.html#Shell-Functions
32 changes: 32 additions & 0 deletions concepts/functions/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ Similarly, _assigning_ a value to a variable will assign it _in the scope where
This "action at a distance" can create hard-to-follow code, as it is not always obvious where a variable was assigned a value.
~~~~

~~~~exercism/advanced
The call stack can be examined using [the `FUNCNAME` array variable][funcname].
[funcname]: https://www.gnu.org/software/bash/manual/bash.html#index-FUNCNAME
~~~~

## Return Values

A function, like any command, has an _exit status_.
Expand Down Expand Up @@ -209,5 +215,31 @@ for i in {1..10}; do fibonacci "$i"; done
# => 89
```

~~~~exercism/advanced
The recursion depth can be controlled with [the `FUNCNEST` variable][funcnest].
```bash
bash -c '
recur() {
echo $1
recur $(($1 + 1))
}
FUNCNEST=5
recur 1
'
```
```none
1
2
3
4
5
environment: line 1: recur: maximum function nesting level exceeded (5)
```
[funcnest]: https://www.gnu.org/software/bash/manual/bash.html#index-FUNCNEST
~~~~

[variables]: https://exercism.org/tracks/bash/concepts/variables
[man-funcs]: https://www.gnu.org/software/bash/manual/bash.html#Shell-Functions

0 comments on commit f72a5cf

Please sign in to comment.