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

Optional Result or _Result var for functions #472

Open
electric-socket opened this issue Mar 14, 2024 · 1 comment
Open

Optional Result or _Result var for functions #472

electric-socket opened this issue Mar 14, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@electric-socket
Copy link

Is your feature request related to a problem? No.
A clear and concise description of what the problem is.

Many other languages have a feature where a function name is aliased to the variable 'RESULT'. This variable is a stand-in alias for the function name. It has the same type as the function and can be used instead of - or in addition to - the function's name as the target of an expression. It can also be used in place of the function's name so that it is clear - especially when the function has no arguments - that the function's result is being used in an expression, and it is not a recursive function call.

As people might use result for other purposes, the pseudo variable _Result could be used.

Describe the solution you'd like
IN some program there is
Dim Table$(100)
.
.
Now, is the following legal?

DefInt C
Function Check (X As String)
For Check = 1 to 100
if X=Table$(Check) then exit function
next
check=0
End function
' The function returns where X was found

This could be used instead:

DEFINT C
integer Function Check(X as string)
' In this case an implicit
'' DIM _Result as Integer
''is inside the function
For _Result = 1 to 100
if X=Table$(_Result) then exit function
next
_result=0 '(or)
Check=0
' Both do the same thing.
End function

Function xx$
result = " "
result = result + Table$(Check("Hello"))
exu

Of course these are contrived examples, but I think having either a variable called _Result (or Result) as a variable implicitly defined as local to that function that is an alias for the function's name would be a useful improvement to the language.

Paul


Paul Robinson [email protected]
"

@electric-socket electric-socket added the enhancement New feature or request label Mar 14, 2024
@a740g
Copy link
Contributor

a740g commented Mar 14, 2024

We have #212. This eventually turned into a similar discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants