Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 23

Thread: print()++

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

    Default

    Take a look at Implicit conversion to strings.

    Here is tbl.ash::

    Code:
    // This data structure is an easier to use representation of KoLmafia's
    // string representation in _beachLayout. It maps row number (an int) to
    // 10-character string of squares, coded as above
    
    typedef string [int] beach_layout;
    
    // Function to convert a string compatible with the _beachLayout
    // property to a beach_layout map
    
    beach_layout to_beach_layout( string squares )
    {
        beach_layout layout;
        foreach i, row_data in squares.split_string( "," ) {
    	int colon = row_data.index_of( ":" );
    	if ( colon != -1 ) {
    	    int row = row_data.substring( 0, colon ).to_int();
    	    string squares = row_data.substring( colon + 1 );
    	    layout[ row ] = squares;
    	}
        }
        return layout;
    }
    
    // Function to convert beach layout map into a string compatible with
    // the _beachLaout property
    
    string to_string( beach_layout layout )
    {
        buffer value;
        foreach row, squares in layout {
    	if ( value.length() > 0 ) {
    	    value.append( "," );
    	}
    	value.append( row );
    	value.append( ":" );
    	value.append( squares );
        }
        return value.to_string();
    }
    
    string test = "2:rrrrrrrrrr,3:rrrrrrrrrc,4:rrrrrrrrrr,5:rrrrrrrrrr,6:rrrrrrrrrr,7:rrrrrrrrrr,8:rrrrrrrrrr,9:crrrrrrrrr,10:rrrrrrrcrr";
    
    beach_layout layout1 = test.to_beach_layout();
    print( layout1.to_string() );
    
    beach_layout layout2 = test;
    print( layout2 );
    Here is the result of invoking that script:

    Code:
    > tbl.ash
    
    2:rrrrrrrrrr,3:rrrrrrrrrc,4:rrrrrrrrrr,5:rrrrrrrrrr,6:rrrrrrrrrr,7:rrrrrrrrrr,8:rrrrrrrrrr,9:crrrrrrrrr,10:rrrrrrrcrr
    2:rrrrrrrrrr,3:rrrrrrrrrc,4:rrrrrrrrrr,5:rrrrrrrrrr,6:rrrrrrrrrr,7:rrrrrrrrrr,8:rrrrrrrrrr,9:crrrrrrrrr,10:rrrrrrrcrr
    This works because:

    1) print( string ARG )
    2) ASH will look up custom to_string( TYPEDEF ) and to_TYPEDEF( string ) functions.
    3) When assigning to a string (or typedef or record) as a variable or function parameter, ASH will auto-coerce using such custom functions.

    Your proposal to change the signature of print() to no longer have a string argument will break this test - and any other script that depends - by eliminating this auto-coercion.

    This is a non-backwards-compatible change that will break MY scripts. Therefore, I don't like it.

    Adding a new runtime function with the "dump" functionality seems OK.
    Breaking print() is not.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  2. #12

    Default

    Veracity (of course) has put it very convincingly. I think creating a new function and naming it dump is a good idea moving forwards.

  3. #13
    Senior Member
    Join Date
    Apr 2019
    Posts
    260

    Default

    If we're making a new function, then should it only accept composite values instead of ANY_TYPE?

  4. #14
    Senior Member
    Join Date
    Apr 2019
    Posts
    260

  5. #15
    Senior Member
    Join Date
    Apr 2019
    Posts
    260

    Default

    Still waiting for a response/review; did I not do things correctly?

  6. #16
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,797

    Default

    Still waiting for a response/review; did I not do things correctly?
    Originally Posted by fredg1 View Post
    Huh?

    Adding a new runtime function with the "dump" functionality seems OK.
    Breaking print() is not.
    Originally Posted by Veracity View Post
    I had not realized you were continuing anyway.

    Just calling it ".patch" doesn't really emphasize to me that there is a file behind the link. My bad but dump.patch might have caught my attention.

    A 30 second look at the patch but not applying it suggests to me that it still contains the changes to print that were objected to. I can look harder to confirm that, but a post that was a little more verbose and acknowledged some of the proposal had been dropped would have gotten my attention sooner.
    Well, thank you.
    Originally Posted by Veracity View Post

  7. #17

    Default

    My opinion is probably near-irrelevant, but I'd just like to add that I've been playing around with the dump command, and it's been really helpful to me when I'm experimenting with scripts. Nothing earth-shatteringly important, but I find the data structures a little confusing at times and being able to 'dump' them out and see what they contain without having to iterate over everything has been really helpful.

    Technical issues aside, concerning which I accept that the opinion of the developers is paramount, if anyone's wondering whether there's any desire for such a command I'm happy to put my hand up and say I'd love to see this incorporated officially, and it's been really helpful to me.

  8. #18
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    13,537

    Default

    It looked like there was some refactoring of print to extract the “add color” part so that dump could use it. To be honest, I don’t understand why you’d want to dump in red, say, but meh. I’ll look at it a bit more and submit (something like) it.

  9. #19
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    13,537

    Default

    Revision 20381

  10. #20
    Senior Member MCroft's Avatar
    Join Date
    Feb 2009
    Posts
    151

    Default

    dump doesn't act as an unknown command in the gCLI, but isn't in help.

    ash dump() works as expected, but it shouldn't be callable the way I did it in the first instance. It probably doesn't make sense if you don't have records to dump.

    Code:
    > dump
    
    Internal error: Illegal type for main() parameter
    > dump rotgut
    
    Bad null value: "rotgut"
    Returned: null
    
    > dump X
    
    Bad null value: "X"
    Returned: null
    Expected unknown command:
    Code:
    > ribbit
    
    Unable to invoke ribbit
    Code:
    > ash record rec{string a;int b;float c;} y= new rec("aaa",10,10.5),z = new rec("bbb",30,9.9);rec[int] map = {0:y,1:z};dump(map,"red")
    
    aggregate rec [int]
    0 => record rec
      a => aaa
      b => 10
      c => 10.5
    1 => record rec
      a => bbb
      b => 30
      c => 9.9
    Returned: void
    Last edited by MCroft; 09-23-2020 at 04:55 PM. Reason: adding successful dump

Posting Permissions

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