Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- KX Community
- :
- Discussion Forums
- :
- kdb+ and q
- :
- Why does the amend form of dot operator creates a ...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2023.02.26 06:59 AM

1 ACCEPTED SOLUTION

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2023.02.27 08:54 AM

This has to do with the behavior of the ' operator (which is each is a wrapper for).

If we have p:.[;();:;] , p is a binary function, as it is a projection with two elided arguments. The ' operator modifies a function to go elementwise on its arguments - and the resulting function has the same arity as the original one. So p' is also a binary function. Applying p' to a single object (in this case a two-element list) only gives it one argument, the other is still missing, so the result is a projection.

In fact each is a wrapper that only works with unary functions. You get the same behavior whenever you try to use each with a non-unary function on the left side. You can only make non-unary functions behave elementwise by directly using the apostrophe and passing the necessary number of arguments.

If we add a dot after the projection: p2:.[;();:;] . , this changes the structure of the expression. The main operator is now the dot, and it is projected with the left argument p. Since the dot is a binary function, projecting it with one argument creates a unary function. Now you can use each with the unary function and a list. And then the dot will do what you would expect - invoke the function on the left (which is p) with the elements on the list on the right as arguments, and since we are iterating over the original list, those arguments will be a table name and an empty table. The original projection p is a fancy way of overwriting a variable. It would work just as well with set:

.[set]each x

has the same effect of assigning the empty table values to the respective tables.

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2023.02.27 03:15 AM

Can you provide more details such as what you are trying to achieve and what the value of x is?

A projection is created whenever there is an elided argument in the argument list, no matter what the argument list is being applied to. In fact this allows you to create projections that have no useful purpose such as f:{x}[;;2] which will always either return another projection or throw a 'rank error.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2023.02.27 04:51 AM

.u.rep: (.[;();:;].)each x

Shouldn't it apply the function to every item in x since we do "each"; it still needs the right-most dot to apply the function to each pair of x

Here, x: x:((`trade;([]time:`time$();sym:`$();price:`float$();size:`int$()));(`quote;([]time:`time$();sym:`$();bid:`float$();bsize:`int$();ask:`float$();asize:`int$())));

Why does it create a projection? (without the right-most dot, it's a projection):

.u.rep: (.[;();:;])each x

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2023.02.27 08:54 AM

This has to do with the behavior of the ' operator (which is each is a wrapper for).

If we have p:.[;();:;] , p is a binary function, as it is a projection with two elided arguments. The ' operator modifies a function to go elementwise on its arguments - and the resulting function has the same arity as the original one. So p' is also a binary function. Applying p' to a single object (in this case a two-element list) only gives it one argument, the other is still missing, so the result is a projection.

In fact each is a wrapper that only works with unary functions. You get the same behavior whenever you try to use each with a non-unary function on the left side. You can only make non-unary functions behave elementwise by directly using the apostrophe and passing the necessary number of arguments.

If we add a dot after the projection: p2:.[;();:;] . , this changes the structure of the expression. The main operator is now the dot, and it is projected with the left argument p. Since the dot is a binary function, projecting it with one argument creates a unary function. Now you can use each with the unary function and a list. And then the dot will do what you would expect - invoke the function on the left (which is p) with the elements on the list on the right as arguments, and since we are iterating over the original list, those arguments will be a table name and an empty table. The original projection p is a fancy way of overwriting a variable. It would work just as well with set:

.[set]each x

has the same effect of assigning the empty table values to the respective tables.

Related Content

- Running user defined aggregation on partitioned tables in kdb+ and q
- why sv needs ,' here? in kdb+ and q
- Amend Entire Works in memory but not with a handle? in kdb+ and q
- Advanced Capstone 1.3 clarification in KX Academy
- Async broadcast to websocket handles using internal function -25! in kdb+ and q

Main Office Contacts

**EMEA**

Tel: +44 (0)28 3025 2242

**AMERICAS**

Tel: +1 (212) 447 6700

**APAC**

Tel: +61 (0)2 9236 5700

Useful Information

Popular Links

Follow Us

KX. All Rights Reserved.

KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.