Results 1 to 3 of 3

Thread: Proposed ASH improvements

  1. #1
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,515

    Default Proposed ASH improvements

    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?
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,821

    Default

    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?
    Originally Posted by Veracity View Post
    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 ...)

  3. #3
    Senior Member zarqon's Avatar
    Join Date
    Nov 2007
    Location
    Seoul, Korea
    Posts
    3,618

    Default

    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.
    Sig by JakAtk
    My scripts: Prefref Plus | Skillref Plus | One-Click Wossna | Om*****st (??) | Psychose-a-Matic | RandBot
    Combat suite: Best Between Battle | Mercenary Mood | SmartStasis | BatMan | BatMan RE
    For script authors: ASH Wiki | ZLib | BatBrain | CLI Links | Drag-n-Drop Inventories | CanAdv | Script Registry | Map Manager
    If you appreciate my work, help me become BAT KING OF THE WORLD! Thanks to all donators!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •