# Allowing arguments on many places in function name

**URL:** https://discourse.julialang.org/t/allowing-arguments-on-many-places-in-function-name/24617
**Category:** Internals & Design
**Tags:** proposal, design
**Created:** [May 26, 2019, 8:11am UTC](https://discourse.julialang.org/t/allowing-arguments-on-many-places-in-function-name/24617 "2019-05-26T08:11:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [May 26, 2019, 8:11am UTC](https://discourse.julialang.org/t/allowing-arguments-on-many-places-in-function-name/24617/1 "2019-05-26T08:11:40Z")

</div>

Here’s a goofy topic for a rainy Sunday. I was pondering this morning how it would look if a function could accept arguments in more than one place, like the following

```julia
(needle)occursin(haystack)

```

rather than the current

```julia
occursin(needle, haystack)

```

This for sure would open up for some code that reads very much like natural language, but would there be significant downsides?

Some potential complications and comments:

- One could probably not allow two consequtive sets of `()()` as that would make it hard to know the sematics of `fun1(a1)(a2)fun2`, are these two functions or one with two args?
- I think one would have to require that at least one sets of `()` end every function call, otherwise it would be difficult to understand what `()producefun()` means, does it return and call a function like `producefun()()` in todays semantics, or is it a single function call?
- All functions `(#1)some(#2)text(#3)` could also automatically define `sometext(#1,#2,#3)` as a fallback.
- This is in some sense a generalization of defining ones own infix operators, as `(a)isa(T)` can already be expressed as `a isa T`

Some nice examples

- `(needle)occursin(haystack)`
- `map(f)over(x)`
- `in(y)store(A)*(b) / store(A)mul(b)in(y)` # Maybe difficult to make work with operators.
- `findfirstin(a)suchthat(x->x>0) `
- `elementsof(a)thatare(>(0))` or `(a)keep(>(0))` instead of `filter(>(0), a)`

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [May 26, 2019, 10:34pm UTC](https://discourse.julialang.org/t/allowing-arguments-on-many-places-in-function-name/24617/2 "2019-05-26T22:34:14Z")

</div>

Breaking, since this syntax already means multiplication:

```julia
julia> (3+2)sin(4)
-3.7840124765396412

```

See also the long discussion in [#16985](https://github.com/JuliaLang/julia/issues/16985) on custom infix operators. The good news is that a vast number of custom infix operators are already available in Julia — in fact, an infinite number, since you can add any number of combining characters, super/subscripts, and a few other characters to existing operators:

```julia
julia> const ∈′ = occursin
occursin (generic function with 6 methods)

julia> "er" ∈′ "better"
true

julia> "er" ∈′ "worse"
false

```

---

<div class="post-metadata">

### Author: ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)
#### Post date: [May 27, 2019, 2:12am UTC](https://discourse.julialang.org/t/allowing-arguments-on-many-places-in-function-name/24617/3 "2019-05-27T02:12:48Z")

</div>

You can abuse the multiplication syntax to make it happen already:

```julia
julia> struct Infix
           f
           rval
       end

julia> Base.:*(x, i::Infix) = i.f(x, i.rval)

julia> occursin(x) = Infix(Base.occursin, x)
occursin (generic function with 1 method)

julia> needle, haystack = "th", "hey there";

julia> (needle)occursin(haystack)
true

```
