Is there a future plan (as in already on the todo list) to support argument / parameters with sub and load.
What is the position on this subject?
sub and load with arguments / parameters
-
Zardoz2293
- Posts: 616
- Joined: 09 Nov 2011 20:20
- Location: USA
sub and load with arguments / parameters
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%
-
admin
- Site Admin
- Posts: 66274
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
-
PeterH
- Posts: 2827
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: sub and load with arguments / parameters
admin wrote:Currently not planned.
Another question: could it be possible to define a sub to share all variables with the calling script, i.e. just to use the same variable pool? For some routines this could be very helpful...
-
Zardoz2293
- Posts: 616
- Joined: 09 Nov 2011 20:20
- Location: USA
Re: sub and load with arguments / parameters
As in a Boolean value? Default = False (current behavior); True = automatically share all local variables within scope between current script and calling? Slick.PeterH wrote:admin wrote:Currently not planned.![]()
![]()
Another question: could it be possible to define a sub to share all variables with the calling script, i.e. just to use the same variable pool? For some routines this could be very helpful...
I think Don would rather provide arguments / parameters. I'll take either
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: sub and load with arguments / parameters
Don, you could alleviate some of the pain by improving Global:
Okay the second is kind of dreaming but it would sure beat listing the variables one by one. 
Code: Select all
Global(*); // For the rest of the script all non-perm. variables are from the global space.
Global('G_*'); // For the rest of the script all non-perm. variables whose names start with "G_" are from the global space.-
PeterH
- Posts: 2827
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: sub and load with arguments / parameters
A I assume, your generic Global commands would, in the moment they are executed, reset all current variables?TheQwerty wrote:Don, you could alleviate some of the pain by improving Global:Okay the second is kind of dreaming but it would sure beat listing the variables one by one.Code: Select all
Global(*); // For the rest of the script all non-perm. variables are from the global space. Global('G_*'); // For the rest of the script all non-perm. variables whose names start with "G_" are from the global space.
OK - you can define Global in the beginning of a script and each of it's subs - but then there are very much dependencies...
General / very much globals are just what I try to avoid in this situation: I want to write a routine (a piece of code that's used several times, maybe read a record and parse it before further use) that shares quite a lot of variables with the calling code, and runs in the same environment as the calling code. (So this should be limited, e.g. only be usable in subs - i.e. code in the same script file.)
This differs from a "normal subroutine", where you prefer *not* to share all variables, but only selective variables (best in form of parameters, or sometimes by defining variables as global).
-
Zardoz2293
- Posts: 616
- Joined: 09 Nov 2011 20:20
- Location: USA
Re: sub and load with arguments / parameters
Frankly, I think if such a thing is done, it would be arguments / parameters and not global variables. The only global things should be constants, enumerations, etc. and I'd like it to make me a Pizza Supreme too. 
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%
-
Twisten
- Posts: 204
- Joined: 27 Apr 2008 10:30
Re: sub and load with arguments / parameters
Too bad its not in the plan, would be very nice if we could add tiny scriptlets that could be called as functions, I see enormous potential in that; Both help avoid code duplication while scripting and as a very shareable way of extending XYplorer.
-
admin
- Site Admin
- Posts: 66274
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: sub and load with arguments / parameters
Of course, user functions with arguments would be a natural extension of the current scripting engine. It might come one day, when I'm bored enough.
FAQ | XY News RSS | XY X
XYplorer Beta Club