Scripting: User-Defined Functions

Features wanted...
admin
Site Admin
Posts: 49474
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 02 May 2015 14:52

In those cases don't indent the include statement.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

Stef123

Re: Scripting: User-Defined Functions

Post by Stef123 » 02 May 2015 14:54

admin wrote:In those cases don't indent the include statement.
Fair enough. Easy enough.

Marco
Posts: 2303
Joined: 27 Jun 2011 15:20

Re: Scripting: User-Defined Functions

Post by Marco » 02 May 2015 16:52

Thank you for the explanations, PeterH and SammaySarkar, and thank you Don for the change - much appreciated! (I must have missed the line immediately following a function has to unindented somewhere in the changelog)

To me, having the included statement at the beginning of the script gives me a peace of mind and a sense of neatness, and is quite logical too - I include things before they are used, and it also reminds me of C code, where # include is mostly (if not always) on top.

Also, good to know that only %things% and <things> are allowed as function default. I somehow noticed that because the workaround

Code: Select all

function myfunction($items = <get "SelectedItemsPathNames" "|">) {
//...various code...
}
works. Well, I guess I could always do

Code: Select all

function myfunction($items) {
 if ("$items" == "") {$items = get("SelectedItemsPathNames", "|");};
//...various code...
}
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Online
PeterH
Posts: 2593
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Scripting: User-Defined Functions

Post by PeterH » 02 May 2015 17:02

First question: why does indentation on the include stmt indent the included lines? Is there an advantage?

If the included lines contain a script, the caption/label seems not to be recognized if indented.

Second: as I understand, if the include is located inside of a script, and a function is included, it will be, from definition to closing }, "moved out of" the current script. (By the way: it's also callable from other scripts then.)
If a script is included, this is not recognized (as a function is) - it's interpreted as a new script starting at the including position - and being appended with the rest of the stmts behind the include. A bit strange...
W7(x64) SP1 German
( +WXP SP3 )

admin
Site Admin
Posts: 49474
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 02 May 2015 17:05

Marco wrote:I must have missed the line immediately following a function has to unindented somewhere in the changelog)
Because it was never meant it to be like that. It's a workaround that just *happened* to work. Now it's not necessary anymore.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

Online
PeterH
Posts: 2593
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Scripting: User-Defined Functions

Post by PeterH » 02 May 2015 17:15

...if you include a function.

Don't try if including a script: the old rule is in effect!
W7(x64) SP1 German
( +WXP SP3 )

admin
Site Admin
Posts: 49474
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 02 May 2015 17:36

This would not work without the new include indentation:

Code: Select all

"#1"
  echo "#1";
"#2"
  include echo.inc
file echo.inc:

Code: Select all

echo "Hi!";
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Scripting: User-Defined Functions

Post by SammaySarkar » 02 May 2015 18:54

This, with the fact that (semi-)inline functions are now allowed almost made me think this will finally work:

Code: Select all

 include "somefile.inc"; text 'yahoo!';
:cry:

ed. all this business with indenation inspired this UDF: dedent(). :kidding:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Online
PeterH
Posts: 2593
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Scripting: User-Defined Functions

Post by PeterH » 03 May 2015 00:13

admin wrote:This would not work without the new include indentation:
Shouldn't code to be included inside a script be indented - just as if you would code it where it belongs?
So in an include file, if you want to start a script, start left (best with a label), if you only want code, indent it. For the way I see these files I would understand this as "natural".

OK: my way to see it. And: if I write the include unindented I can use it as I expect, I think.
W7(x64) SP1 German
( +WXP SP3 )

SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Scripting: User-Defined Functions

Post by SammaySarkar » 03 May 2015 07:13

introduce another preprocessor that enforces particular indentation on a line, else the line gets indented as include.
Such as this birdbrained example

Code: Select all

<<0"demo"
  hi;
the caption will always be unindented when included.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

nerdweed
Posts: 593
Joined: 25 Feb 2012 07:47

Re: Scripting: User-Defined Functions

Post by nerdweed » 03 May 2015 17:10

binocular222 wrote:We can have a default.inc, which is always loaded in RAM. Scripts doesn't need to explicitly include this file. The "include" line is only needed for user-created *.inc other than default.inc.
I second this. :tup:

Also, how can we call UDF's from outside (like AHK) as the include wouldn't work in a one liner and without the include statement, as the function definition would be unknown.

admin
Site Admin
Posts: 49474
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 03 May 2015 19:13

binocular222 wrote:We can have a default.inc, which is always loaded in RAM. Scripts doesn't need to explicitly include this file. The "include" line is only needed for user-created *.inc other than default.inc.
A good idea, but ... if the default.inc is large (and it will become large) it will slow down even the smallest scripts, including column scripts.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

Online
PeterH
Posts: 2593
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Scripting: User-Defined Functions

Post by PeterH » 04 May 2015 12:41

admin wrote:
binocular222 wrote:We can have a default.inc, which is always loaded in RAM. Scripts doesn't need to explicitly include this file. The "include" line is only needed for user-created *.inc other than default.inc.
A good idea, but ... if the default.inc is large (and it will become large) it will slow down even the smallest scripts, including column scripts.
An organizational question?

If each function of this type is pre-parsed (as is on include) when loaded, then moved to a "Preloaded Function Storage", the only thing XY must know about each function is Name and Location.
Only when any function is called, XY just must scan this list - (only) if the name is found, it will be touched. So the result is "like" a real XY-internal function.

Must think about: search order:
- pre-loaded first for high speed
- pre-loaded last, so in name conflict local function is executed
(Might be a use case for name spaces?)

Every user is responsible for the amount of pre-loaded functions.
XY-statistics (like Various Information) should show number and storage for pre-loaded.

Yes: some work to do. But as, in between the time, you treat a function "from definition to ending }" as one entity, it seems possible.
W7(x64) SP1 German
( +WXP SP3 )

admin
Site Admin
Posts: 49474
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Scripting: User-Defined Functions

Post by admin » 04 May 2015 12:52

PeterH wrote:Only when any function is called, XY just must scan this list ...
In every script all strings followed by "(" could be a user function and have to be tested against all loaded user functions. This can add up...
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

Online
PeterH
Posts: 2593
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Scripting: User-Defined Functions

Post by PeterH » 04 May 2015 13:11

admin wrote:
PeterH wrote:Only when any function is called, XY just must scan this list ...
In every script all strings followed by "(" could be a user function and have to be tested against all loaded user functions. This can add up...
Are'nt they also tested against all internal functions?
W7(x64) SP1 German
( +WXP SP3 )

Post Reply