Page 1 of 1

Function varargs (ie for recursion,to simplify logic, etc..)

Posted: 10 Jun 2016 04:09
by Acecool
Variable arguments helps simplify some functions greatly..

I use recursion frequently in a lot of other languages when it makes sense to do so, but you don't need to use recursion to have benefits from variable arguments...

One such example is one of my functions to format debug text into columns ( I'll be posting a topic on the issues with calculating font-size in pixels or even having the font use uniform spacing so I can do the same in XYplorer ), string.FormatColumn( _width, _text, ... ) which recurses by calling itself and only passing ... to the new call effectively shifting the arguments in ... to _width and _text so they can be used ( if new args exist of course )... string.FormatSimpleColumn( _width, _text, ... ) is similar, but it calls string.FormatColumn, the only difference is you don't need to set a width for every column of text, ie they're all uniform so it shifts ... over 1 and re-uses _width..

I've been looking through the reference guide and I haven't found any reference to this... The only options seem to be spamming args ( long text ) or a "List", ie a text blob with delimiters which would then need to be parsed to output the data which is what I will be doing for now but I'd definitely like to see varargs!

Re: Function varargs (ie for recursion,to simplify logic, et

Posted: 10 Jun 2016 07:27
by bdeshi
You're right. That's not supported in XYscript.