# Dynamically project function

**URL:** <https://forum.kx.com/t/dynamically-project-function/12985>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [August 17, 2023, 4:32pm UTC](https://forum.kx.com/t/dynamically-project-function/12985 "2023-08-17T16:32:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![erichards1](https://avatars.discourse-cdn.com/v4/letter/e/7feea3/32.png) [@erichards1](https://forum.kx.com/u/erichards1)\
**Post date:** [August 17, 2023, 4:32pm UTC](https://forum.kx.com/t/dynamically-project-function/12985/1 "2023-08-17T16:32:00Z")

</div>

Two questions on function projection&nbsp;

Firstly, how can I project a function to one with no args, i.e. deferred execution.

```
fn: {[x] x+1};

```

Obviously _fn[1]_ or _fn&nbsp;@ 1_ will invoke the function now. Is there a way without wrapping it in another fn?

&nbsp;

Secondly, how can I dynamically project a function, e.g.

```
fn: {[x;y;z] x+y-z};
args: (1; ::; 3);

```

I’d like to achieve the equivalent of \_fn[1; ; 3], h\_owever _fn . args_ invokes the function now with the second parameter as null rather than returning a projection.

&nbsp;

Thanks

---

<div class="post-metadata">

**Author:** ![gyorokpeter-kx1](https://avatars.discourse-cdn.com/v4/letter/g/d26b3c/32.png) [@gyorokpeter-kx1](https://forum.kx.com/u/gyorokpeter-kx1)\
**Post date:** [August 17, 2023, 4:52pm UTC](https://forum.kx.com/t/dynamically-project-function/12985/2 "2023-08-17T16:52:00Z")

</div>

In reality there is no such thing as a “zero-argument function” in q. Even if you don’t have an argument list and you don’t use any of x, y and z in your function, or if you specify the argument list as , the function still has one argument. If you call a function with “no arguments” , that actually means calling it with :: as an argument.

Projection for the purpose of a deferred function call is achieved by adding a dummy argument, e.g. instead of

```
fn: {[x] x+1};

```

you would have

```
fn: {[x;u] x+1};

```

then fn[1] creates a projection that will execute the calculation with any argument passed.

For the second question, one possible way is by composing a projection of enlist with the dot-apply of your function:

q)proj:(')[fn .;(1; ; 3)]; q)proj .[{[x;y;z] x+y-z}]enlist[1;;3] q)proj 2 0 q)proj 10 8

&nbsp;
