# Extract arguments type and defalut value from a Function

**URL:** https://discourse.julialang.org/t/extract-arguments-type-and-defalut-value-from-a-function/19505
**Category:** New to Julia
**Tags:** question
**Created:** [January 11, 2019, 5:21am UTC](https://discourse.julialang.org/t/extract-arguments-type-and-defalut-value-from-a-function/19505 "2019-01-11T05:21:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![orange\_si](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orange_si/32/6526_2.png) [@orange\_si](https://discourse.julialang.org/u/orange_si)
#### Post date: [January 11, 2019, 5:21am UTC](https://discourse.julialang.org/t/extract-arguments-type-and-defalut-value-from-a-function/19505/1 "2019-01-11T05:21:49Z")

</div>

hello, everyone,  
I want to extract arguments type and defalut value from a Function, but method() only give part of arguement type and no defalut value which are defined by function.

```julia
function hello(name::String="world";greet::String="nice day")
    println("hello $name, $greet")
end
methods(hello)

```

will output this:

```julia
2 methods for generic function hello:
    hello(name::String; greet) in Main at In[6]:2
    hello() in Main at In[6]:2

```

Is there other ways to do this？

I am using julia1.0.2，thanks ~

Regards

---

<div class="post-metadata">

### Author: ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)
#### Post date: [January 11, 2019, 5:53am UTC](https://discourse.julialang.org/t/extract-arguments-type-and-defalut-value-from-a-function/19505/2 "2019-01-11T05:53:47Z")

</div>

```julia
dump([m for m in methods(hello)])

```

shows information for both methods.

```julia
julia> [m for m in methods(hello)][1].roots[2]
"nice day"

```

But I have no idea if there is an official public API to get at this kind of info.

---

<div class="post-metadata">

### Author: ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)
#### Post date: [January 11, 2019, 9:00am UTC](https://discourse.julialang.org/t/extract-arguments-type-and-defalut-value-from-a-function/19505/3 "2019-01-11T09:00:26Z")

</div>

I tried to address a similar problem with a macro recently.  
See [here](https://discourse.julialang.org/t/retrieve-default-values-of-keyword-arguments/19320).

---

<div class="post-metadata">

### Author: ![orange\_si](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orange_si/32/6526_2.png) [@orange\_si](https://discourse.julialang.org/u/orange_si)
#### Post date: [January 11, 2019, 9:12am UTC](https://discourse.julialang.org/t/extract-arguments-type-and-defalut-value-from-a-function/19505/4 "2019-01-11T09:12:37Z")

</div>

thanks very much~ then I tried this, it can get the name and greet default name, but no number argument.

```julia
function hello(name::String="world";greet::String="nice day",number::Int=3)
    println("x")
end
methods(hello)
for m in methods(hello)
    println(m.roots)
end

```

and output this

```julia
Any[Symbol("#hello#36"), "nice day", :hello, Symbol("In[35]")]
Any["world", :hello, Symbol("In[35]")]

```

---

<div class="post-metadata">

### Author: ![orange\_si](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orange_si/32/6526_2.png) [@orange\_si](https://discourse.julialang.org/u/orange_si)
#### Post date: [January 11, 2019, 9:21am UTC](https://discourse.julialang.org/t/extract-arguments-type-and-defalut-value-from-a-function/19505/5 "2019-01-11T09:21:22Z")

</div>

@jandehaan @jbrea yes, I hoped there is a public API for this.
