Scripting: User-Defined Functions

Features wanted...
TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: Scripting: User-Defined Functions

Post by TheQwerty » 11 May 2015 16:25

admin wrote:I plan to officially release functions and include in 15.20. The features work alright for everybody now? (Not asking for extra wishes -- those will come in phase 2.)
Include does not work well for me.

Mainly because of this:

Code: Select all

v15.00.0507 - 2015-04-26 12:58
. . .
    + Scripting: Now Include statements can be nested (included files can 
      themselves include other files). The maximum nesting level for Include 
      statements is 100 (one hundred). You will get an error if you go beyond.
      Beware of recursion: **A file must not include itself or any file by which 
      it has been included**, else you will reach the maximum nesting level within 
      the next millisecond...      
(emphasis mine)

If I have two include files which rely on functions within each other there's no good way to get it to work.

Unfortunately, you complicated it further with these bizarre changes:

Code: Select all

v15.00.0523 - 2015-05-02 14:58
. . .
    * Scripting: Now include, function, and namespace statements can be indented.
      - Makes scripts look better.
      - Included stuff will now inherit the indent of the include statement. Can 
        make a difference in multiscripts.
Which makes it very tempting to use include for things other than functions.


As far as I can tell this will never work given the current behavior...

ArgIs.inc:

Code: Select all

include String.inc

namespace ArgIs

function Integer($arg) {
  return ($arg == 0) || ($arg\1 == $arg);
}

function EmptyString($arg) {
  return String::IsEmpty($arg);
}
String.inc:

Code: Select all

include ArgIs.inc

namespape String

function Repeat($str, $repeat=0) {
  Assert ArgIs::Integer($repeat), 'Repeat must be an integer.';
  Assert $repeat >=0, 'Repeat must be non-negative.';

  return StrRepeat($str, $repeat);
}

function IsEmpty($str) {
  return $str == '';
}
Script.xys:

Code: Select all

include String.inc

"Repeat"
  echo String::Repeat('Hello', 2);
But from my perspective this should be entirely possible and the recursion shouldn't happen because XY should maintain a list of included files and not include the same file more than once.


Also, reusing a popular extension in 'inc' is a terrible choice in my opinion - 'xyi' or 'xysi' would be better.

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

Re: Scripting: User-Defined Functions

Post by admin » 11 May 2015 17:17

Hm, I don't plan to make circular includes work. It's bad coding.

But I might add an include_once statement in a later version. It will allow you to do what you did.

Apart from being "tempting" (I have no problem with that) I see no issues with indented include. If you don't like the indent don't use it. :)
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Wear a mask! 😷

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

Re: Scripting: User-Defined Functions

Post by TheQwerty » 11 May 2015 17:44

admin wrote:Hm, I don't plan to make circular includes work. It's bad coding.

But I might add an include_once statement in a later version. It will allow you to do what you did.
Then the foundation of UDF is not solid enough to start building future scripts on.


EDIT:
admin wrote:Apart from being "tempting" (I have no problem with that) I see no issues with indented include. If you don't like the indent don't use it. :)
I think it creates more support issues than it solves. It also makes it confusing as to when the file is included - indenting makes it seem like it is pulled in during script execution, but that's not the case.

Post Reply