# Double function definition

**URL:** <https://discourse.julialang.org/t/double-function-definition/61330>\
**Category:** General Usage\
**Tags:** functions\
**Created:** [May 17, 2021, 11:01pm UTC](https://discourse.julialang.org/t/double-function-definition/61330 "2021-05-17T23:01:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 17, 2021, 11:01pm UTC](https://discourse.julialang.org/t/double-function-definition/61330/1 "2021-05-17T23:01:57Z")

</div>

Wondering if it is possible to define two functions with the same sugar as for variable definition (ex: `x, y = 1.0, -pi`):

```julia
h(x,y), g(x,y) = y-x, y-2x # Error
(h,g)(x,y) = y-x, y-2x # OK but what is it?
h(1,1), g(1,1) # Error
(h,g)(1,1) # Error

```

Thanks for shedding some light on this.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [May 17, 2021, 11:06pm UTC](https://discourse.julialang.org/t/double-function-definition/61330/2 "2021-05-17T23:06:25Z")

</div>

```julia
h,g = (x,y)->y-x, (x,y) -> y-2*x

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [May 17, 2021, 11:07pm UTC](https://discourse.julialang.org/t/double-function-definition/61330/3 "2021-05-17T23:07:55Z")

</div>

How does that happen?

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [May 17, 2021, 11:14pm UTC](https://discourse.julialang.org/t/double-function-definition/61330/4 "2021-05-17T23:14:03Z")

</div>

A la `x, y = 1.0, -pi`, it assigns to two variables, `h` and `g`. The values assigned to the variables are anonymous functions. It’s the same as this, just less readable:

```julia
h = (x,y) -> y - x
g = (x,y) -> y - 2*x

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 17, 2021, 11:19pm UTC](https://discourse.julialang.org/t/double-function-definition/61330/5 "2021-05-17T23:19:48Z")

</div>

Would it be fair to classify your code as smart but not necessarily as sugar?  
The amount of verbose increases and sugar (by definition?) should reduce it?

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [May 17, 2021, 11:21pm UTC](https://discourse.julialang.org/t/double-function-definition/61330/6 "2021-05-17T23:21:46Z")

</div>

I’d decline both characterizations. Concise is good as long as it clarifies. Combining the definitions on a single line does not add clarity.
