cancel
Showing results for 
Search instead for 
Did you mean: 

Basic (but still intriguing to me) q Interpreter question

JP
New Contributor III

A bit at lost here... Can someone enlighten me as to how the interpreter works in the following situation:

q)show a:10?(-1 0 1)   //Just to have something
0 1 1 0 -1 0 1 -1 0 0

q)(>)a    //That's the curiosity
1 2 6 0 3 5 8 9 4 7

I understand this is actually the same as...

q)raze where each a=/:desc distinct a  
1 2 6 0 3 5 8 9 4 7

but... can't figure out where this is coming from(!)

Thx in advance

 

1 ACCEPTED SOLUTION

cillianreilly
New Contributor III

Hi JP, this is just the underlying k implementation of idesc: https://code.kx.com/q/ref/desc/#idesc

 

q)a:0 1 1 0 -1 0 1 -1 0 0
q)idesc
k){$[0h>@x;'`rank;>x]}
q)idesc[a]~(>)a
1b
q)\
  >a
1 2 6 0 3 5 8 9 4 7

 

The brackets allow q to interpret this, but the use is discouraged (https://code.kx.com/q/basics/exposed-infrastructure/#unary-forms). Rather use the idesc keyword instead.

View solution in original post

2 REPLIES 2

cillianreilly
New Contributor III

Hi JP, this is just the underlying k implementation of idesc: https://code.kx.com/q/ref/desc/#idesc

 

q)a:0 1 1 0 -1 0 1 -1 0 0
q)idesc
k){$[0h>@x;'`rank;>x]}
q)idesc[a]~(>)a
1b
q)\
  >a
1 2 6 0 3 5 8 9 4 7

 

The brackets allow q to interpret this, but the use is discouraged (https://code.kx.com/q/basics/exposed-infrastructure/#unary-forms). Rather use the idesc keyword instead.

JP
New Contributor III

Feel ashamed(!)... I realize I shouldn't have skipped that <k> part of the language:-)

Thx again