KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy Scripting and logging question

  • Scripting and logging question

    Posted by Jonathan on August 27, 2024 at 2:31 pm

    Hi,

    I am working on module 08 scripting and logging and I’m a bit confused on the following example in the image.

    I don’t understand why we need to use the stdout function “out” to display the results of the list multiplication? I thought if we used the multivalent trap “.”, it would display the results of the multiplication if no errors were found. But I tried running it without the out function and it wouldn’t display the results and I’m confused as to why.

    Any help would be appreciated,

    Thank you!

    rocuinneagain replied 2 weeks, 6 days ago 2 Members · 4 Replies
  • 4 Replies
  • rocuinneagain

    Member
    August 27, 2024 at 2:42 pm

    If a line ends in ; then the output is not displayed.

    $ cat test.q
    a:til 10
    f:{x*y}
    f[a;5]; /Not displayed
    f[a;200] /Displayed
    f[a;.01]; /Not displayed
    $ q test.q
    0 200 400 600 800 1000 1200 1400 1600 1800
    q)
    • rocuinneagain

      Member
      August 27, 2024 at 2:49 pm

      Note that -1 will display items differently than letting q display them

      $ cat test.q
      a:til 10
      f:{"the answer is "," "sv string x*y}
      f[a;200] //Result will print but include "" around it
      f2:{-1 "the answer is "," "sv string x*y}
      f2[a;200] //Result printed to standard out does not display "". -1 is also shown as the returned value.
      f2[a;200]; // Same as above but ; suppresses -1 bring shown
      f3:{-1 "the answer is "," "sv string x*y;}
      f3[a;200] //; moved inside the function to supress -1
      $q test.q
      "the answer is 0 200 400 600 800 1000 1200 1400 1600 1800" //f[a;200]
      the answer is 0 200 400 600 800 1000 1200 1400 1600 1800 //f2[a;200]
      -1 //f2[a;200] continued
      the answer is 0 200 400 600 800 1000 1200 1400 1600 1800 //f2[a;200];
      the answer is 0 200 400 600 800 1000 1200 1400 1600 1800 //f3[a;200]
    • Jonathan

      Member
      August 27, 2024 at 2:50 pm

      Completely forgot it does that. It’s working now, thank you.

      • rocuinneagain

        Member
        August 27, 2024 at 2:54 pm
        q)reply:"\360\237\221\215"
        q)reply
        "\360\237\221\215"
        q)-1 reply;
        👍

Log in to reply.