sub and load with arguments / parameters

Discuss and share scripts and script files...
Post Reply
Zardoz2293
Posts: 616
Joined: 09 Nov 2011 20:20
Location: USA

sub and load with arguments / parameters

Post by Zardoz2293 »

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?
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%

admin
Site Admin
Posts: 66260
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: sub and load with arguments / parameters

Post by admin »

Currently not planned.

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

Post by PeterH »

admin wrote:Currently not planned.
:cry: :cry: :cry:

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

Post by Zardoz2293 »

PeterH wrote:
admin wrote:Currently not planned.
:cry: :cry: :cry:

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...
As in a Boolean value? Default = False (current behavior); True = automatically share all local variables within scope between current script and calling? Slick. :shock:

I think Don would rather provide arguments / parameters. I'll take either :D
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%

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: sub and load with arguments / parameters

Post by TheQwerty »

Don, you could alleviate some of the pain by improving Global:

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.
Okay the second is kind of dreaming but it would sure beat listing the variables one by one. :mrgreen:

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

Post by PeterH »

TheQwerty wrote:Don, you could alleviate some of the pain by improving Global:

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.
Okay the second is kind of dreaming but it would sure beat listing the variables one by one. :mrgreen:
A I assume, your generic Global commands would, in the moment they are executed, reset all current variables?
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

Post by Zardoz2293 »

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. 8)
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%

Twisten
Posts: 204
Joined: 27 Apr 2008 10:30

Re: sub and load with arguments / parameters

Post by Twisten »

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: 66260
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: sub and load with arguments / parameters

Post by admin »

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.

Post Reply