# How to let a function return some numerical values and a graph simutaneously?

For example:

``````using UnicodePlots

function func(n)
r = randn(n)
s = sum(r)
hist = histogram(r, nbins=10, closed=:left)
r, s, hist
end
``````

If I call this function in the REPL, it returns:

``````julia> func(10)
([1.5369990699727945, -0.7353913882824294, -0.8568141947726255, 1.145149668937184, 0.3340140471550356, 1.2364301576354533, 1.8932925331172032, 0.05768487009000112, -0.2116877502737839, 0.4638080551886433], 4.863485068767476,                 β                                        β
[-1.0, -0.5) β€βββββββββββββββββββββββββ 2
[-0.5,  0.0) β€βββββββββββββ 1
[ 0.0,  0.5) β€βββββββββββββββββββββββββββββββββββββ  3
[ 0.5,  1.0) β€  0
[ 1.0,  1.5) β€βββββββββββββββββββββββββ 2
[ 1.5,  2.0) β€βββββββββββββββββββββββββ 2
β                                        β
Frequency                 )
``````

As seen, the histogram is returned as an element of the tuple, which makes it display sickly. Is there any good solutions to this issue? Thanks.

Doesnβt this do what you want already? If you want to display the histogram separately, do

``````julia> r, s, hist = func(10);
julia> hist
``````

or

``````julia> func(10)[3]
``````
1 Like