recall the result from ProcedureReturn

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

recall the result from ProcedureReturn

Post by Realizimo »

is this a god idea

Code: Select all

Procedure test()
  ProcedureReturn 1  
EndProcedure
If test(): a=getp(): Debug a: EndIf ; getp()=recall the result from ProcedureReturn
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: recall the result from ProcedureReturn

Post by Caronte3D »

Code: Select all

Procedure test()
  ProcedureReturn 1  
EndProcedure
a=test()
If a: Debug a: EndIf
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: recall the result from ProcedureReturn

Post by Realizimo »

of course i know that, Caronte3D, this is not a good idea or?
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: recall the result from ProcedureReturn

Post by jacdelad »

I don't think that's a good idea, too. Storing into a variable is easy and your proposed function would have to handle different data types. Also it gets more and more complicated when using threads (which don't return anything, but can calls functions which return values) and such.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: recall the result from ProcedureReturn

Post by Realizimo »

ok, thanks
BarryG
Addict
Addict
Posts: 4135
Joined: Thu Apr 18, 2019 8:17 am

Re: recall the result from ProcedureReturn

Post by BarryG »

Why would this be a good idea? ProcedureReturn already returns any result, which you can store in a variable or structure. Why would a new command be needed to do the same thing?
Quin
Addict
Addict
Posts: 1131
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: recall the result from ProcedureReturn

Post by Quin »

Yeah, I must say I'm not sure what you're after. It's possibly a language barrier, but it sounds like what you want to do is store the result of a procedure. We have variables for that. If this is wrong, though, feel free to clarify.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: recall the result from ProcedureReturn

Post by AZJIO »

As you can see, you can store the results of the last operation performed in a structure, but this will use memory. AutoIt3 at least has "error" and "extended" variables that contain some function execution data as statistics for internal functions that you cannot change to add statistics. Initially, it was unusual for me to determine the operation of a function only by the returned result. But it's not hard to do. The only rule is that these results are valid only until the next function call; after calling another function, these results will determine the state of another function.

Code: Select all

EnableExplicit

Structure ProcedureStatus
  string.s
  integer.i
  error.i
  extended.i
EndStructure

Global g_ProcedureStatus.ProcedureStatus


Procedure.s ReplaceStringAndCount(String$, s = 1, o = 0)
	Protected Count
; 	reset variable values ​​before use
	g_ProcedureStatus\error = 0
	g_ProcedureStatus\extended = 0
	g_ProcedureStatus\integer = 0
	g_ProcedureStatus\string = ""
; 	perform any actions
	Count = CountString(String$, " ")
	String$ = ReplaceString(String$ , " " , "_" , #PB_String_CaseSensitive, s, o)
; 	save the results of the function in the form of statistics, which are declared in the function description
	If Count = 0
		g_ProcedureStatus\error = 1
	EndIf
	g_ProcedureStatus\extended = Count
	g_ProcedureStatus\string = String$
    ProcedureReturn String$
EndProcedure

; After performing the replacement operation, obtain the number of replacements, the error status and,
; taking this into account, take any actions, for example, recognize the operation as unsuccessful
Debug ReplaceStringAndCount("go go go")
Debug g_ProcedureStatus\extended
Debug g_ProcedureStatus\error
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: recall the result from ProcedureReturn

Post by Realizimo »

Quin
yes it what I want, but , I think nicer/shorter code, but I understand that I am just lazy. sorry
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: recall the result from ProcedureReturn

Post by HeX0R »

oh, o.k., lazy coder, like me?
I sometimes also need something like that, I typically solve it like this:

Code: Select all

Procedure test(*R.INTEGER)
	*R\i = 1
  ProcedureReturn 1  
EndProcedure
If test(@a)
	Debug a
EndIf
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: recall the result from ProcedureReturn

Post by the.weavster »

I made a feature request for the walrus operator

So then your example would become:

Code: Select all

Procedure test()
  ProcedureReturn 1  
EndProcedure

If a := test()
    Debug a
EndIf
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: recall the result from ProcedureReturn

Post by Realizimo »

the.weavster
Better than my way :D
Post Reply