Page 1 of 1
sub and load with arguments / parameters
Posted: 31 Jan 2012 11:35
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?
Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 12:10
by admin
Currently not planned.
Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 12:40
by PeterH
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...
Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 13:12
by Zardoz2293
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...
As in a Boolean value? Default = False (current behavior); True = automatically share all local variables within scope between current script and calling? Slick.
I think Don would rather provide arguments / parameters. I'll take either

Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 13:41
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.

Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 14:02
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.

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).
Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 14:20
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.

Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 16:28
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.
Re: sub and load with arguments / parameters
Posted: 31 Jan 2012 18:02
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.