Running K scripts in Q

Hi,

I’m trying to run this script in q.

/ K script<o:p></o:p>

/ 04-k22014-VoteCount.k<o:p></o:p>

j22014:{[votes]<o:p></o:p>

  s:(+/“A”='votes),+/“B”='votes;<o:p></o:p>

  :(“Tie”;“A”;“B”)@(~=/s)*1+*>s<o:p></o:p>

}<o:p></o:p>

/ I get this error.

q)\l 04-k22014-VoteCount.k

k){0N!x y}

'char

@

“k”

"\357\273\277j22014:{[votes]\n   s:(+/"A"='votes),+/"B"='votes;\n   :("T..

q))

Where is the error in my code? I’m too green to debug this. Ideally, I want to write functions and multiline q or k scripts.

Thanks,
Will

Directly copying and pasting that poses a different issue than the one you are having…the lack of an indent before your trailing lambda. So be sure to fix that if it’s also an issue in your file (or happens after you fix this one).

You could copy and paste the code in this thread into a new file, indent the lambda, and it should run fine.

The error you have is 'char (invalid character - http://code.kx.com/wiki/Errors). kdb+ uses only 7-bit ascii.

You can see the specific erroneous part of your code in this line

"\357\273\277j22014:{[votes]\n   s:(+/"A"=‘votes),+/"B"=’votes;\n :("T..

note the “\357\273\277”.

that’s a BOM - http://www.markhneedham.com/blog/2012/09/03/a-rogue-357273277-utf-8-byte-order-mark/, and you need to remove it.

not sure what OS/editor you use, but in vim you can open the file, and run :set nobomb to remove the leading BOM mark. - http://vim.1045645.n5.nabble.com/How-to-display-and-remove-BOM-in-utf-8-encoded-file-td4681708.html

replicated below:

cat script.k

jj22014:{[votes]

   s:(+/“A”='votes),+/“B”='votes;

   :(“Tie”;“A”;“B”)@(~=/s)*1+*>s

 }

qq script.k

..fine..

vi script.k

:set bomb

cat script.k

jj22014:{[votes]

   s:(+/“A”='votes),+/“B”='votes;

   :(“Tie”;“A”;“B”)@(~=/s)*1+*>s

 }

qq script.k

k){0N!x y}

'char

@

“k”

"\357\273\277jj22014:{[votes]\n   s:(+/"A"='votes),+/"B"='votes;\n   :("..

q))\

HTH,

Sean