# Functional assignment

**URL:** <https://forum.kx.com/t/functional-assignment/6347>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [November 17, 2009, 1:51pm UTC](https://forum.kx.com/t/functional-assignment/6347 "2009-11-17T13:51:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![annakh71](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@annakh71](https://forum.kx.com/u/annakh71)\
**Post date:** [November 17, 2009, 1:51pm UTC](https://forum.kx.com/t/functional-assignment/6347/1 "2009-11-17T13:51:00Z")

</div>

I am having trouble with that. First: @[`.d;`t;:;2] / fails with `type error .d.t: 0 / .d.t is now defined @[`.d;`t;:;2] / now worksWhy does .d.t have to be defined for the functional form of assignmentto workand what is the remedy? Second: @[`.d;`t;:] 2 / fails with `type error @[`.d;`t;:] @ 2 / fails with `type error {@[`.d;`t;:;x]} 2 / worksI can live with having to define an explicit function but why do Ihave to?Thanks

---

<div class="post-metadata">

**Author:** ![Attila](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Attila](https://forum.kx.com/u/Attila)\
**Post date:** [November 17, 2009, 3:33pm UTC](https://forum.kx.com/t/functional-assignment/6347/2 "2009-11-17T15:33:00Z")

</div>

.d.t: syntax makes sure that .d is a namespace  
for amend to work you have to initialize it  
for example:  
.[`.d;();:;1#.q]  
then  
@[`.d;`t;:;2]  
works fine

> ? @[`.d;`t;:] 2 ? ? ?/ fails with `type error ? @[`.d;`t;:] @ 2 ?/ fails with `type error  
> ? {@[`.d;`t;:;x]} 2 / works

@[`.d;`t;:[;2]]

Regards,  
?Attila

---

<div class="post-metadata">

**Author:** ![annakh71](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@annakh71](https://forum.kx.com/u/annakh71)\
**Post date:** [November 17, 2009, 4:02pm UTC](https://forum.kx.com/t/functional-assignment/6347/3 "2009-11-17T16:02:00Z")

</div>

\> for amend to work you have to initialize .dRight. It’s not t that was the problem but .d. Makes sense (after thefact). Oneeasily forgets that the “prompt” forms have quite a bit of syntacticsugar thatis missing from the functional forms.\> @[`.d;`t;:[;2]]That’s not what I was looking for. I was trying to come up with aunary verb thattakes a value and assigns it to .d.t

---

<div class="post-metadata">

**Author:** ![Attila](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Attila](https://forum.kx.com/u/Attila)\
**Post date:** [November 17, 2009, 4:13pm UTC](https://forum.kx.com/t/functional-assignment/6347/4 "2009-11-17T16:13:00Z")

</div>

\> @[`.d;`t;:[;2]]

> That’s not what I was looking for. I was trying to come up with a  
> unary verb that  
> takes a value and assigns it to .d.t

f:@[`.d;`t;:;]

f 10

but possibly it is the best to use set (which is .[;();:;])

`.d.t set 2

that works fine without having d initialized  
?? Attila

---

<div class="post-metadata">

**Author:** ![annakh71](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@annakh71](https://forum.kx.com/u/annakh71)\
**Post date:** [November 17, 2009, 5:08pm UTC](https://forum.kx.com/t/functional-assignment/6347/5 "2009-11-17T17:08:00Z")

</div>

OK. I had failed to remember that there is a ternary form of @(protected execution), so you need the trailing ;] to make it aunary verb.Thanks a lot.
