-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concept: functions #715
base: main
Are you sure you want to change the base?
Concept: functions #715
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still in WIP/Draft state...
concepts/functions/introduction.md
Outdated
function funcname { COMMANDS; } | ||
``` | ||
|
||
There is no difference between the two styles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we recommend the portable syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal preference, based on my time in the IRC channel, is for the portable version.
Mentioning two approaches without any suggestion in one direction or the other can leave someone new to the syntax a bit ... confused/adrift about which to use.
concepts/functions/introduction.md
Outdated
function funcname { COMMANDS; } | ||
``` | ||
|
||
There is no difference between the two styles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal preference, based on my time in the IRC channel, is for the portable version.
Mentioning two approaches without any suggestion in one direction or the other can leave someone new to the syntax a bit ... confused/adrift about which to use.
concepts/functions/introduction.md
Outdated
``` | ||
~~~~ | ||
|
||
## Return Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A function call has one return value. A function can have many calls and many return values.
A function variable has one name and one value (at any given time).
It feels very odd to me for them to be inconsistent.
## Recursion | ||
|
||
Functions can call themselves recursively. | ||
By default, there is no limit to the depth of recursion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No recursion limit ... but factorials would overflow pretty quickly 😄
95ba5c4
to
0626d48
Compare
Regarding the 2 ways to define a function, I simply removed one of them. Frustratingly even the google shell style guide mixes the styles. |
Otherwise, the variable is placed in the _global scope_. | ||
|
||
Local variables can have the same name as a global variable. | ||
In that case, the local variable _temporarily_ overrides the global one, and the global value is restored when the function returns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we explain this in a different way, where it is more clear what is happening. Effectively, the description is accurate, but the global value is only overwritten, not in a state where it must be restored, it is not like it was "gone" or "delete". Is this, maybe, a situation where the lookup table order matters, and when found we do not look for anything else with the same name?
The global really did not go anywhere, it is more like the name of the variable is found, and so there is no reason to continue looking, the next place to look being from the local scope to the global scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the diff view, maybe it is explained well in lines +72 to +73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking about this, but I have a holiday cold so I can't real concentrate ATM
Functions concept