Concatenation issue for atomic values

https://learninghub.kx.com/forums/topic/concatenation-issue-for-atomic-values

Hi guys,

When i’m doing <strong>$("1";"0")</strong> it is automatically showing as <strong>"10"</strong>. Is there any way i can make it as <strong>1`0

A single character .i.e “1” is a type -10h
A list of characters .i.e “10” is a type 10h
You can create a single character list using ‘enlist’ .i.e

q)type each ("1";"0";"11-15") /Some are lists some are not 
-10 -10 10h 
q)type each (enlist "1";enlist "0";"11-15") /All are lists 
10 10 10h 
q)("1";"0") 
"10" 
q)type each ("1";"0") 
-10 -10h 
q)(enlist "1";enlist "0") //Using enlist to make single character lists 
,"1" ,"0" 
q)type each (enlist "1";enlist "0") 
10 10h

Using ‘enlist’ will help prevent unwanted concatenation for you.
https://code.kx.com/q/ref/enlist/

You can use each-right to cast each character one at a time:

https://code.kx.com/q/ref/maps/#each-left-and-each-right

q) `$“10”

`10

q) `$/:“10”

10

 

Hey, thanks for your input here but to be more clear

if i’m having a table like this

t:(Vals:`$(“1”;“0”;“10”))

if i’m passing the parameters as 1 and 0 means it should return 1 and 0 from table t. Also if i’m passing as 10 it should return as 10

 

Currently it is showing the results as 1 and 0 for both 1,0 and 10. Please check the attached screenshot

 

All of these items are equivalent:

 

q)"10" 
"10" 
q)("1";"0") 
"10" 
q)("10") 
"10"

 

They all resolve to 2 item lists containing characters

https://code.kx.com/q/basics/datatypes/

Here are some more example queries which may help:

 

q)select from t where Vals in `$/:("1";"10") 
Vals 
---- 
1 10 

q)select from t where Vals in `$/:("1";"0") 
Vals 
---- 
1 0 

q)select from t where Vals in `$"10" 
Vals 
---- 
10 

q)select from t where Vals in `$"1" 
Vals 
---- 
1

 

You can use ‘=’ rather than ‘in’ if you are searching for only one value:

q)select from t where Vals=`$"1" 
Vals 
---- 
1

You can input your symbols directly rather than casting:

q)0110 0110

 

Hi , in my case i’m giving a multiselect option which may pass 1 or 0 or 10 or 11-15 or Above 15 etc.. So that i’m facing this issue

q))$(“1”;“0”;“11-15”)
1011-15 q))$(“1”;“0”)
10 q))$(“10”)
`10

So user may select anything from the list together.

Hey , this really helps. I used the type to see when the user selects multiple values.

q))type (“1”;“0”)
10h
q))type (“1”;“10”)
0h

So based on that i added the condition now which works fine for my scenario. Thanks a lot !!