# Working on the editor - the g/fnk macro

**URL:** <https://forum.defold.com/t/working-on-the-editor-the-g-fnk-macro/67457>\
**Category:** Source Code\
**Created:** [February 4, 2021, 12:01am UTC](https://forum.defold.com/t/working-on-the-editor-the-g-fnk-macro/67457 "2021-02-04T00:01:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![otsakir](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/otsakir/32/24694_2.png) [@otsakir](https://forum.defold.com/u/otsakir)\
**Post date:** [February 4, 2021, 12:01am UTC](https://forum.defold.com/t/working-on-the-editor-the-g-fnk-macro/67457/1 "2021-02-04T00:01:43Z")

</div>

Can someone explain what is this `fnk` clojure macro in ns dynamo.graph? It’s defined in dynamo/graph.clj. It’s used all over the place but its definition is kind of cryptic.

I’ve come across this on a sound issue i’m working on and seems i need to sort this out to properly handle default values on a property and validation.

Thanks

[https://github.com/defold/defold/issues/3514](https://github.com/defold/defold/issues/3514)

---

<div class="post-metadata">

**Author:** ![mats.gisselson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mats.gisselson/32/3379_2.png) [@mats.gisselson](https://forum.defold.com/u/mats.gisselson)\
**Post date:** [February 4, 2021, 8:28am UTC](https://forum.defold.com/t/working-on-the-editor-the-g-fnk-macro/67457/2 "2021-02-04T08:28:27Z")

</div>

The `g/fnk` macro is used in node definitions to define the input dependencies and calculate the resulting value of an output. Each name in the argument list corresponds to an input, output or property on the node the `g/fnk` is used in. When the output that hosts the `g/fnk` is evaluated, each of the names inputs are evaluated and then fed as arguments into the `g/fnk`. You could view it as a regular `fn` with added metadata about its dependencies.

---

<div class="post-metadata">

**Author:** ![mats.gisselson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mats.gisselson/32/3379_2.png) [@mats.gisselson](https://forum.defold.com/u/mats.gisselson)\
**Post date:** [February 4, 2021, 8:29am UTC](https://forum.defold.com/t/working-on-the-editor-the-g-fnk-macro/67457/3 "2021-02-04T08:29:32Z")

</div>

If you don’t want to inline the `g/fnk` in the node definition, you could use `g/defnk` to create a named `fnk` outside the node and refer to it by name instead.

---

<div class="post-metadata">

**Author:** ![otsakir](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/otsakir/32/24694_2.png) [@otsakir](https://forum.defold.com/u/otsakir)\
**Post date:** [February 4, 2021, 8:55am UTC](https://forum.defold.com/t/working-on-the-editor-the-g-fnk-macro/67457/4 "2021-02-04T08:55:49Z")

</div>

Thanks mats.ggisselson for you clean explanation.

I see cases where an input dependency of a property is the property itself. Is this typical ?

---

<div class="post-metadata">

**Author:** ![mats.gisselson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mats.gisselson/32/3379_2.png) [@mats.gisselson](https://forum.defold.com/u/mats.gisselson)\
**Post date:** [February 4, 2021, 9:14am UTC](https://forum.defold.com/t/working-on-the-editor-the-g-fnk-macro/67457/5 "2021-02-04T09:14:58Z")

</div>

Yes, that is normal. If a `g/fnk` is used for the `value` form of a property declaration, the input to the `g/fnk` will be the “raw” value of the property, and whatever the `g/fnk` returns will be the value of the property that the outside world sees.

This is used a lot for situations like where a property was assigned a resource path, but then the resource was moved on disk. You want the outside world to see the new path to the moved resource.
