Double function definition

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

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.

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

How does that happen?

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:

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

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?

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

2 Likes