Lists - Selection from a list

Hi! Good Moorning!

Today is a holiday in my city. I’m taking the opportunity to continue studying q and kdb+.

I am currently reviewing lists. I made several examples using the selection functions.

Function: x sublist y

q) l:(1 3 5 7 2 4 6 8)

q) 3 sublist l

1 3 5

q) -3 sublist l

4 6 8

q) 3 4 sublist l     / where x is an integer pair

7 2 4 6

Doubt:

How can I use a variable in place of fixed integers?

q) x:3

q) y:4

q) x y sublist l

Thanks again for your help!
Best regards!

The following will work: (x;y) sublist l

The reason being that when you place integers one space apart, kdb will  implicitly convert this to a list, so 

type 3 4 = 7h,  a list of integers.

This is not the case for variables. For example:

q) x:{x+1}

q) y:4

q) x y 

5

So as we can see in this case placing them side by side had the effect of applying x to y. So in order to preserve the behaviour, we write (x;y) to tell kdb this is explicitly a list, and not to apply them to one another

Best wishes,

Chad 

Hey hope you’re enjoying your holiday:

 

f:{(x;y) sublist l} 

f[3;4] 

will give your desired result. 

The reason why x y sublist l won’t work is  kdb reads from right to left. It runs this command x (y sublist l).

Hope this helps,

Dan

Hi!

While looking for a solution to the question with the sublist function,

I wrote the code below to display part of a list from a point:

q)l:(1 3 5 7 9 2 4 6 8)

q)myF:{[qtd;i;l1] do[qtd; show l1[i]; i+:1]}

q)myF[4;3;l]

7

9

2

4

It is certainly not the ideal solution.

If anyone can show me an optimized code, I appreciate it.

Thanks again for your help!
Best regards!

Em terça-feira, 13 de outubro de 2020 às 11:28:40 UTC-3, Geraldo M Melo Jr escreveu:

Hi! Good Moorning!

Today is a holiday in my city. I’m taking the opportunity to continue studying q and kdb+.

I am currently reviewing lists.I made several examples using the selection functions.

Function: x sublist y

q) l:(1 3 5 7 2 4 6 8)

q) 3 sublist l

1 3 5

q) -3 sublist l

4 6 8

q) 3 4 sublist l     / where x is an integer pair

7 2 4 6

Doubt:

How can I use a variable in place of fixed integers?

q) x:3

q) y:4

q) x y sublist l

Thanks again for your help!
Best regards!

q)L:1 3 5 7 2 4 6 8
q)x:3 4
q)x sublist L
7 2 4 6

q) / or..

q)x:3
q)y:4
q)(x;y)sublist L
7 2 4 6




Stephen Taylor | Librarian | Kx | +44 7713 400852 | stephen@kx.com

Stephen Taylor, good afternoon!
Thank you!

I didn’t understand the need for the integer pair to be a list.

Guys, I’m sorry for posting these simple questions.

Today is my second day with the language and I’m excited.

Solution presented:

q)l:(1 3 5 7 9 2 4 6 8)

q) x: 3

q) y: 4

q) (x; y) sublist l

Tanks!!!

Em terça-feira, 13 de outubro de 2020 às 12:16:29 UTC-3, ste...@kx.com escreveu:

q)L:1 3 5 7 2 4 6 8
q)x:3 4
q)x sublist L
7 2 4 6

q) / or..

q)x:3
q)y:4
q)(x;y)sublist L
7 2 4 6




Stephen Taylor | Librarian | Kx | +44 7713 400852 | ste…@kx.com

Chad, thank you so much!

Thank you for the explanation.

This explanation complemented the solution presented by Stephen Taylor.

Best regards!

Em terça-feira, 13 de outubro de 2020 às 12:35:37 UTC-3, chad....@gmail.com escreveu:

The following will work: (x;y) sublist l

The reason being that when you place integers one space apart, kdb will  implicitly convert this to a list, so 

type 3 4 = 7h,  a list of integers.

This is not the case for variables. For example:

q) x:{x+1}

q) y:4

q) x y 

5

So as we can see in this case placing them side by side had the effect of applying x to y. So in order to preserve the behaviour, we write (x;y) to tell kdb this is explicitly a list, and not to apply them to one another

Best wishes,

Chad 

Dan, thank you!

 I will spend the day studying q language.

Do you have online courses?

Em terça-feira, 13 de outubro de 2020 às 12:35:50 UTC-3, dan.sh...@aquaq.co.uk escreveu:

Hey hope you’re enjoying your holiday:

 

f:{(x;y) sublist l} 

f[3;4] 

will give your desired result. 

The reason why x y sublist l won’t work is  kdb reads from right to left. It runs this command x (y sublist l).

Hope this helps,

Dan

Hello Geraldo

You can also drop the parentheses from around the long list. Q inherited that simple vector notation from APL; hard to believe it has been available for over half a century. (A colleague once complained: APL – still an improvement on its successors.)

There are tutorials at code.kx.com/q/learn. There is much I want to improve there. So I am interested in any obstacles you encounter.

If you get a moment: what language/s have you used recently, and what excites you about what you are learning?

Best

Stephen

Stephen Taylor | Librarian | Kx | +44 7713 400852 | stephen@kx.com

Hello, Stephen.

> “There are tutorials at code.kx.com/q/learn.”

I am using your website as the main source of study.

> “So I am interested in any obstacles you encounter.”

Thanks!

> “If you get a moment: what language/s have you used recently, …”

The main languages: C/C ++, Python and Clojure.

Database: MySQL, MongoDB e Datomic.

I’m doing a postgraduate degree in Data Science.

We are using Python (Numpy, Pandas, …) and R.

> “… and what excites you about what you are learning?”

Hobbie: IOT (Arduino)
I found Q and KDB +, I fell in love :-)

Best

Geraldo

Em terça-feira, 13 de outubro de 2020 às 13:59:11 UTC-3, ste...@kx.com escreveu:

Hello Geraldo

You can also drop the parentheses from around the long list. Q inherited that simple vector notation from APL; hard to believe it has been available for over half a century. (A colleague once complained: APL – still an improvement on its successors.)

There are tutorials at code.kx.com/q/learn. There is much I want to improve there. So I am interested in any obstacles you encounter.

If you get a moment: what language/s have you used recently, and what excites you about what you are learning?

Best

Stephen


Stephen Taylor | Librarian | Kx | +44 7713 400852 | ste…@kx.com

Hey AquaQ also offers online courses available here: 

https://kdbtraining.aquaq.co.uk/

There’s plenty of further information about the training on the website 

All The Best,

Dan

Dan, good morning! 
Thank you!

I accessed the site and I’m doing the basic module for free.

Very good!

Best regards!

Geraldo 

Em qua, 14 de out de 2020 11:36, Dan Sheppard <dan.sheppard@aquaq.co.uk> escreveu:

Hey AquaQ also offers online courses available here: 

https://kdbtraining.aquaq.co.uk/

There’s plenty of further information about the training on the website 

All The Best,

Dan