# Julep: Taking multiple dispatch,export,import,binary compilation seriously

**URL:** https://discourse.julialang.org/t/julep-taking-multiple-dispatch-export-import-binary-compilation-seriously/10882
**Category:** Internals & Design
**Tags:** namespaces
**Created:** [May 14, 2018, 9:58am UTC](https://discourse.julialang.org/t/julep-taking-multiple-dispatch-export-import-binary-compilation-seriously/10882 "2018-05-14T09:58:33Z")
**Posts on this page:** 1
**Showing post:** 118

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [May 18, 2018, 3:41am UTC](https://discourse.julialang.org/t/julep-taking-multiple-dispatch-export-import-binary-compilation-seriously/10882/118 "2018-05-18T03:41:11Z")

</div>

@jlperla was interested in having a macro for merging function definitions automatically.

[https://github.com/chakravala/ForceImport.jl/issues/1](https://github.com/chakravala/ForceImport.jl/issues/1)

this is actually not that difficult to write a macro for so I created the `@merge` macro, but note that macros cannot be used for code generation, so the `eval` method must be called on the output of the macro.

Here is an example

```nohighlight
julia> using ForceImport

julia> module Mod
           export fun
           fun(x) = x
       end
Mod

julia> using Mod

julia> eval(@merge fun(x::String) = String)
fun (generic function with 2 methods)

julia> fun(1)
1

julia> fun("1")
String

```

So with the `eval(@merge fun...)` macro, the `Mod.fun` method is automatically imported if necessary.

Here is the macro definition

```nohighlight
macro merge(expr)
    if !( (expr.head == :function) | ( (expr.head == :(=)) &&
            (typeof(expr.args[1]) == Expr) && (expr.args[1].head == :call) ) )
        throw(error("ForceImport: $expr is not a function definition"))
    end
    fun = expr.args[1].args[1]
    return Expr(:quote,quote
        for name in names(current_module())
            try
                eval(ForceImport.imp($(string(fun)),name))
            end
        end
        eval($(Expr(:quote,expr)))
    end)
end

function imp(fun::String,name::Symbol)
    :(Symbol($fun) ∈ names($name) && (import $name.$(Symbol(fun))))
end

```

---

_[View the full topic](https://discourse.julialang.org/t/julep-taking-multiple-dispatch-export-import-binary-compilation-seriously/10882)._
