Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 23

Thread: print()++

  1. #1
    Senior Member
    Join Date
    Apr 2019
    Posts
    260

    Default print()++

    You know how, when you do "ash <command>" on the CLI, if you end with a record or an aggregate, mafia will tell you the content of the record/aggregate? Print now does that, always.

    1st, this moves the "dump" function that was in AshSingleLineCommand.java and puts it in RuntimeLibrary.java (AS PUBLIC; trying to make sure I get your attention here, Veracity, to be sure you're not against that).


    2nd, the two print functions now accept any datatype. If they get sent a string, they print it, as normal, and the function ends. If it's NOT a string, they turn it into a string, and sends it back to them. Then, they look at the datatype of what they initially had, and if it's a composite, they send it to dump() (which now supports colors, too!).

    Proof of concept: javaw_LsZ5WoEd4b.png

    I'm pretty sure there's things that can be improved, such as taking care of the cleaning of the color's string at the start and only passing "that" around, but I'm... currently quite eager to go to sleep, so I'll put this here, let you guys look at it and leave feedback, and if there's anything wrong, I can take care of it tomorrow. G'night (well... it's almost 8Am... :| )

    .patch

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

    Default

    If they get sent a string, they print it, as normal, and the function ends. If it's NOT a string, they turn it into a string, and sends it back to them
    Originally Posted by fredg1 View Post
    I had an error in expectations concerning print(a + b) when a and b were both integers. I was expecting that print would see two integers and an addition operator but what was happening was two integers were coerced into strings and then concatenated. Does this patch change, perhaps inadvertently, that behavior?
    Well, thank you.
    Originally Posted by Veracity View Post

  3. #3
    Senior Member Crowther's Avatar
    Join Date
    Nov 2006
    Posts
    1,584

    Default

    I would expect all these to produce the same result:
    Code:
    string s1 = 2 + 2;
    int two = 2;
    string s2 = two + two;
    print(s1);
    print(s2);
    print(2+2);
    print(two+two);
    And they do: 4. I can understand expecting them all to produce 22, but I don't like that. Print certainly shouldn't be special.

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

    Default

    I would expect all these to produce the same result:
    Code:
    string s1 = 2 + 2;
    int two = 2;
    string s2 = two + two;
    print(s1);
    print(s2);
    print(2+2);
    print(two+two);
    And they do: 4. I can understand expecting them all to produce 22, but I don't like that. Print certainly shouldn't be special.
    Originally Posted by Crowther View Post
    See https://kolmafia.us/showthread.php?2...ing#post157799

    Just want to make sure that the behavior expected by others is preserved :-)
    Well, thank you.
    Originally Posted by Veracity View Post

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

    Default

    I had an error in expectations concerning print(a + b) when a and b were both integers. I was expecting that print would see two integers and an addition operator but what was happening was two integers were coerced into strings and then concatenated. Does this patch change, perhaps inadvertently, that behavior?
    Originally Posted by fronobulax View Post
    javaw_8RV7blSHRl.png

    This seems to already be the normal behavior?? If not, you'll need to be more specific on the context.

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

    Default

    Sorry. I'm having real trouble with written English today.

    I am looking for reassurance that this will not change existing behavior, specifically precedence relationships involving coercion and and operators in print statements.

  7. #7
    Senior Member
    Join Date
    Apr 2019
    Posts
    260

    Default

    oh, ok.javaw_cJhoyUpshS.png

    It seems to behave the same

  8. #8
    Senior Member
    Join Date
    Apr 2019
    Posts
    260

    Default

    Additionally, two things.

    First: if you notice, on the image I attached in my previous message, you can see that the "print" functions (as well as "to_json") now say "null" as their expected value when using "ashref".
    This comes from THIS: Attachment 9768

    Should it be changed to "any"?



    Second: I noticed that in my new/modified version, whenever I input a CLI command, a full extra linebreak is added at the end, whereas only a few pixels were added previously.
    (short video which I hope clarifies what I mean)
    I can't seem to get what change I made could possibly cause this.

  9. #9

    Default

    Sorry. I'm having real trouble with written English today.

    I am looking for reassurance that this will not change existing behavior, specifically precedence relationships involving coercion and and operators in print statements.
    Originally Posted by fronobulax View Post
    If we're ever going to break old scripts (which we do!) this seems like a very reasonable behaviour to change.

  10. #10
    Senior Member
    Join Date
    Apr 2019
    Posts
    260

    Default

    I... don't think that way?

    An integer + an integer should give a new integer, even if the addition is done "on top" of a function that expects a string...

Posting Permissions

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