Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Concept: functions #715

wants to merge 1 commit into from

Conversation

glennj
Copy link
Contributor

@glennj glennj commented Dec 20, 2024

Functions concept

@glennj glennj marked this pull request as draft December 20, 2024 23:23
@glennj glennj requested a review from a team December 20, 2024 23:23
Copy link
Member

@kotp kotp left a 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 Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
function funcname { COMMANDS; }
```

There is no difference between the two styles.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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 Show resolved Hide resolved
concepts/functions/introduction.md Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Show resolved Hide resolved
function funcname { COMMANDS; }
```

There is no difference between the two styles.
Copy link
Member

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.

```
~~~~

## Return Value
Copy link
Member

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.

concepts/functions/introduction.md Outdated Show resolved Hide resolved
concepts/functions/introduction.md Outdated Show resolved Hide resolved
## Recursion

Functions can call themselves recursively.
By default, there is no limit to the depth of recursion.
Copy link
Member

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 😄

@glennj glennj marked this pull request as ready for review December 27, 2024 16:06
@glennj
Copy link
Contributor Author

glennj commented Dec 27, 2024

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.
Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

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

@glennj glennj changed the title WIP Concept: functions Concept: functions Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants