KX Community

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

Home Forums KX Academy like comparison

  • like comparison

    Posted by lestat-jin on April 3, 2024 at 3:42 pm

    Hi:

     

    not sure why for the below two like comparison, the first one returns 1 and second type error? given both are comparing a symbol on the left to its equivalent in string.

     

    `IBM like "IBM" 
    `t like "t"

     

    thanks,

    lestat-jin replied 8 months, 3 weeks ago 3 Members · 4 Replies
  • 4 Replies
  • lestat-jin

    Member
    April 3, 2024 at 3:43 pm

    it does not get shown properly but IBM and t should be symbol type,

  • pgyorok

    Member
    April 3, 2024 at 3:53 pm

    like takes a string on the right. “IBM” is a string. “t” is not a string but a character – this is a quirk in the syntax. If you want to have a one-character string you have to use enlist, in this case enlist”t”.

  • rocuinneagain

    Member
    April 3, 2024 at 3:57 pm
    q)type"t" // t is a character atom - 'like' expects a character vector 
    -10h 
    q)type"IBM" // IBM is a character vector 
    10h 
    q)type enlist "t" // You can enlist an atom to be a single item vector 
    10h 
    q)type (),"t" // (), is useful as a conditional enlist. It enlists the atom 
    10h 
    q)type (),"IBM" // It does not enlist the vector 
    10h
  • lestat-jin

    Member
    April 3, 2024 at 4:47 pm

    Thank you both!

Log in to reply.