# Command that calls functions without the need of arguments

**URL:** <https://discourse.julialang.org/t/command-that-calls-functions-without-the-need-of-arguments/9853>\
**Category:** New to Julia\
**Created:** [March 21, 2018, 10:52am UTC](https://discourse.julialang.org/t/command-that-calls-functions-without-the-need-of-arguments/9853 "2018-03-21T10:52:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LS64](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ls64/32/3743_2.png) [@LS64](https://discourse.julialang.org/u/LS64)\
**Post date:** [March 21, 2018, 10:52am UTC](https://discourse.julialang.org/t/command-that-calls-functions-without-the-need-of-arguments/9853/1 "2018-03-21T10:52:16Z")

</div>

Hey there.

I wrote a longer code for a simulation and now I have a simple problem, but don’t know the best way to solve it.

While working on my simulation loop part, I need to “reset” my input variables. That means, I want to read INI-files again, initialize some basic properties again and reset arrays which have been filled within the last run of my simulation. Of course, I can do this by running the whole code or the initialization part again.

But I would like to have something like “reset()”, that I can type in the console and that’s it. Maybe in such a way:

```julia
command SimReset()
 a = dosomething1(b,c,d)
 e,f = dosomething2(g,h)
 i,j = importINI(k)
 ...
end

```

Is there any possibility to accomplish something like this?

Thanks.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 21, 2018, 11:00am UTC](https://discourse.julialang.org/t/command-that-calls-functions-without-the-need-of-arguments/9853/2 "2018-03-21T11:00:00Z")

</div>

Please

1. [quote code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530),
2. provide a [MCVE](https://stackoverflow.com/help/mcve).

Generally, you would have your problem contained in a structure, bound to a variable, and you can simply implement a `reset(problem::MyProblemType)` method.

---

<div class="post-metadata">

**Author:** ![LS64](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ls64/32/3743_2.png) [@LS64](https://discourse.julialang.org/u/LS64)\
**Post date:** [March 21, 2018, 3:34pm UTC](https://discourse.julialang.org/t/command-that-calls-functions-without-the-need-of-arguments/9853/3 "2018-03-21T15:34:27Z")

</div>

@Tamas_Papp: Thank you, I have edited my first post and will provide a better example. You are absolutely right, it is indispensable.

Here is an example. But because I have not really a problem in terms of error messages, I just give the structure of my code and use `[...]` to abbreviate some content here.

```julia
### initialization
function read_INI_files()
  IN_configINI = Inifile()
  IN_calcINI = Inifile()
  IN_envINI = Inifile()
  read(IN_configINI, joinpath(dirname(@ __FILE__ ),"config.ini"))
  read(IN_calcINI, joinpath(dirname(@ __FILE__ ),"calc.ini"))
  read(IN_envINI, joinpath(dirname(@ __FILE__ ),"env.ini"))
  return(IN_configINI, IN_calcINI, IN_envINI)
end
function evaluate_INI_files(IN_configINI, IN_calcINI, IN_envINI)
  [...]
end
IN_configINI, IN_calcINI, IN_envINI = read_INI_files()
IN_CalculationProperties, IN_N_StoragesToday, IN_N_RatesToday, IN_SupportValues, IN_SimStart, IN_SimEnd, IN_Δt = evaluate_INI_files(IN_configINI, IN_calcINI, IN_envINI)

### general properties
function initialize_TimeStep(IN_SimStart, IN_SimEnd, IN_Δt)
  [...]
end

function initialize_Storages(IN_N_StoragesToday)
  [...]
end

SM_N_Storages = initialize_Storages(IN_N_StoragesToday)
SM_SimStart, SM_SimEnd, SM_Δt, SM_SimSteps, SM_TimeStep = initialize_TimeStep(IN_SimStart, IN_SimEnd, IN_Δt)

# ------------------------------------------------------------------------------
### simulation

include("processes/Atm_N-1.1.jl")
include("processes/Lith_N-1.1.jl")
for SM_t in range(1, Int(SM_SimSteps) - 1)
  [...]

```

At the moment I work at the simulation part (below the dashed line), but sometimes I need to change input variables. For this, I don’t want to call all functions individually. Instead of typing in the console…

```julia
IN_configINI, IN_calcINI, IN_envINI = read_INI_files()
IN_CalculationProperties, IN_N_StoragesToday, IN_N_RatesToday, IN_SupportValues, IN_SimStart, IN_SimEnd, IN_Δt = evaluate_INI_files(IN_configINI, IN_calcINI, IN_envINI)
SM_N_Storages = initialize_Storages(IN_N_StoragesToday)
SM_SimStart, SM_SimEnd, SM_Δt, SM_SimSteps, SM_TimeStep = initialize_TimeStep(IN_SimStart, IN_SimEnd, IN_Δt)

```

…I want to write something like…

```julia
reset()

```

Is there any easy possibility to bundle this?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 21, 2018, 3:39pm UTC](https://discourse.julialang.org/t/command-that-calls-functions-without-the-need-of-arguments/9853/4 "2018-03-21T15:39:10Z")

</div>

To use something like `reset()`, you would need to use globals. This is possible, but encourages bad style.

Instead, I would just pack everything to a structure, eg

```julia
struct Model
    config
    calc
    env
    calculation_properties
    ...
end

```

break the initialization of this into steps/stages (depending on what you can reuse, package a group of variables to structs), and then have a single `reset!(m::Model)` function that works on this.

---

<div class="post-metadata">

**Author:** ![LS64](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ls64/32/3743_2.png) [@LS64](https://discourse.julialang.org/u/LS64)\
**Post date:** [March 21, 2018, 3:47pm UTC](https://discourse.julialang.org/t/command-that-calls-functions-without-the-need-of-arguments/9853/5 "2018-03-21T15:47:24Z")

</div>

Wonderful! I am just reading the documentation of struct in Julia, due to your hint in your other post.

I will try this. Thanks a lot, sounds feasible and useful.
