Proposed ASH improvements

Veracity

Developer
Staff member
1) I wrote the following line of code and got annoyed.

Code:
	int delay = min( min( min( min( semirare_delay, voter_delay ), ghost_delay ), mayfly_delay ), turns );
Why can't ASH have a varargs feature like modern Java?

Code:
	int delay = min( semirare_delay, voter_delay, ghost_delay, mayfly_delay, turns );
where the "min" function would be declared like this:

Code:
int min( int value... );
or, equivalently:

Code:
int min( int[] value );
Either way, when we parse a function call and are looking for a matching function, if we find an "int" argument and discover a function whose final argument is an "int[]", we match the two and build an array with the rest of the ints.

I wonder how hard that would be?

2) We have special handling for the main() function. If you give it arguments, you can call it with arguments in the CLI or not - in which case you are prompted for the arguments.

I'd like to be able to optionally specify a default to avoid the prompts.

Code:
void main( string command )
Always requires a "command" and behaves as now. Perhaps:

Code:
void main( string command = "my default command" )
would let you specify a command in the CLI and set that variable, as now, or simply call the script with no arguments and it will receive the default value as specified in the script.

I guess some clarification is needed for behavior if you have multiple arguments and not all of them specify a default value. We bind supplied arguments to parameters, as now, and when we run out arguments, do we prompt only for those which did not specify a default?

Thoughts?
 

xKiv

Active member
I guess some clarification is needed for behavior if you have multiple arguments and not all of them specify a default value. We bind supplied arguments to parameters, as now, and when we run out arguments, do we prompt only for those which did not specify a default?

Thoughts?

How do you tell the difference between "specified an empty string" and "did not specify this argument"?

Probably best to require all arguments after the first default value tho also have default values (and just start filling defaults after user-specified values run out),
or take a page from languages that have a call mechanism where you specify argument name for each parameter (which would then have to look, in ash, something like main(f=>"first",g=>"second",h=>"third"); - no idea how to make that look in CLI)

(unless you just declare that empty string *is* the same as unspecified value. Have you ever tried explaining how the empty string is NULL in oracle? Fun stuff handling that exception-to-the-rule everywhere that handles string values ...)
 

zarqon

Well-known member
For 1), I love the flexibility that would add. Some care would probably have to be taken to make sure that a script's

min(<specific number of int parameters>)

function would be seen as conflicting with (attempting to override) the library function

min(int...)

but I doubt that's something you haven't already thought of.
 
Top