Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kdb/tick Syntax to Latest Versions (Specifically 4.1) #1

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

chraberturas
Copy link

Description

This PR updates the syntax of the kdb/tick library to adapt latest changes in native language.

Changes Made

  • Reviewed and modified the existing codebase to adhere to the syntax changes introduced in the new versions of kdb+/q.

Additionally, I've made some minor changes resulting in code that is more concise.
@chraberturas chraberturas added the enhancement New feature or request label Feb 27, 2024
@chraberturas chraberturas self-assigned this Feb 27, 2024
Copy link

@tortolavivo23 tortolavivo23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the comments at the beginning of the code, there are comments explaining the last changes, and it indicates the current version and the last update time, consider adding it.

tick/r.q Outdated Show resolved Hide resolved

add:{$[(count w x)>i:w[x;;0]?.z.w;.[`.u.w;(x;i;1);union;y];w[x],:enlist(.z.w;y)];(x;$[99=type v:value x;sel[v]y;@[0#v;`sym;`g#]])}

sub:{if[x~`;:sub[;y]each t];if[not x in t;'x];del[x].z.w;add[x;y]}
sub:{[x:{$[not x in t,`;'x;x]};y]if[x~`;:sub[;y]each t];del[x].z.w;add[x;y]}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose to add

,`

at the end of the condition?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I have been able to guess, since the ifs' are switched, you need to check if x is the null symbol on the first condition as well, and this can be achieved using in, like it has been done here. Still, I don't really see the point of doing this unless we get a speed benefit of some sort.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I just added it because I tried to incorporate the new syntax as much as possible. I need to measure how fast or slow this is, so once I do that, I'll determine if it's worthwhile or not

tick.q Outdated Show resolved Hide resolved
Copy link

@nipsn nipsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have to download v4.1 and actually run these functions to see if the results are the ones expected, so I will add more comments in the future when I get around to do that.


sel:{$[`~y;x;select from x where sym in y]}
sel:{(select from x where sym in y;x)`~y}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are not getting a performance bonus from the new implementation I think I would revert back to its previous version, since it's a bit confusing. When reading the code, you look for a conditional statement, but you get something else.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the main reason for this change was because it's shorter :)
I still believe it's quite clear, so I'll keep it until our master @neutropolis makes the decision

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, just to drag my point across, should we change all ifs to this syntax?

(then;)cond;

I.e:

if[x~`;:sub[;y]each t];
// to
(:sub[;y]each t];)x~`;

Haven't tested it yet, but I'll do so whenever I get to download v4.1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not new in 4.1. We are simply indexing. For example, in this case, x~ will return 0b or 1b. The idea is to index and return the first or second position from the list on the right. I believe this is suitable for small and simple cases.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point still stands. I personally would keep it as it was, but if we are changing it then we should keep it consistent and change every instance of a conditional statement OR every if/else ($) statement. Let's wait to see what @neutropolis has to say about this.


add:{$[(count w x)>i:w[x;;0]?.z.w;.[`.u.w;(x;i;1);union;y];w[x],:enlist(.z.w;y)];(x;$[99=type v:value x;sel[v]y;@[0#v;`sym;`g#]])}

sub:{if[x~`;:sub[;y]each t];if[not x in t;'x];del[x].z.w;add[x;y]}
sub:{[x:{$[not x in t,`;'x;x]};y]if[x~`;:sub[;y]each t];del[x].z.w;add[x;y]}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I have been able to guess, since the ifs' are switched, you need to check if x is the null symbol on the first condition as well, and this can be achieved using in, like it has been done here. Still, I don't really see the point of doing this unless we get a speed benefit of some sort.

tick/u.q Outdated Show resolved Hide resolved
tick/sym.q Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants