# Function definition

**URL:** <https://discourse.julialang.org/t/function-definition/34403>\
**Category:** New to Julia\
**Created:** [February 10, 2020, 10:09am UTC](https://discourse.julialang.org/t/function-definition/34403 "2020-02-10T10:09:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samantp](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@samantp](https://discourse.julialang.org/u/samantp)\
**Post date:** [February 10, 2020, 10:09am UTC](https://discourse.julialang.org/t/function-definition/34403/1 "2020-02-10T10:09:10Z")

</div>

So I want to define a new function, probit, from functions that I use in the SpecialFunctions toolbox. i.e. the function itself is a variant of a function found in this toolbox.  
Right now I have the following

```julia
function probit(t)
    using SpecialFunctions
    return 0.5*(1+erf(t/sqrt(2)))
end

```

However I figure that having to load the SpecialFunctions package every time this function is called may not be the most efficient way of doing things. Is there some way to import just the erf function and therefore save some time?  
Alternately could I just make it so that this function returns an error if the SpecialFunctions package has not been loaded somehow?

Thanks

EDIT: Actually when I run the above I get an error: “syntax: “using” expression not at top level”

so should I just keep this at the top of my function definition file?

---

<div class="post-metadata">

**Author:** ![davidbp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidbp/32/463_2.png) [@davidbp](https://discourse.julialang.org/u/davidbp)\
**Post date:** [February 10, 2020, 10:14am UTC](https://discourse.julialang.org/t/function-definition/34403/2 "2020-02-10T10:14:02Z")

</div>

This should work, `using SpecialFunctions: erf`

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [February 10, 2020, 10:17am UTC](https://discourse.julialang.org/t/function-definition/34403/3 "2020-02-10T10:17:24Z")

</div>

I think the important bit here is that the using statement does not belong into the function definition, but at the top level, for example at the beginning of the file where you define the function `probit`.

```julia

julia> function probit(t)
           using SpecialFunctions
           return 0.5*(1+erf(t/sqrt(2)))
       end
ERROR: syntax: "using" expression not at top level

```

Edit: Yes, exactly. Then it is also clear that the problem that you anticipate “load the SpecialFunctions package every time this function runs” does not happen.
