# Calling a function with 2 arguments of type Float64 and a struct, via its dotted version

**URL:** https://discourse.julialang.org/t/calling-a-function-with-2-arguments-of-type-float64-and-a-struct-via-its-dotted-version/49817
**Category:** New to Julia
**Created:** [November 9, 2020, 1:43am UTC](https://discourse.julialang.org/t/calling-a-function-with-2-arguments-of-type-float64-and-a-struct-via-its-dotted-version/49817 "2020-11-09T01:43:16Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [November 9, 2020, 2:47am UTC](https://discourse.julialang.org/t/calling-a-function-with-2-arguments-of-type-float64-and-a-struct-via-its-dotted-version/49817/2 "2020-11-09T02:47:39Z")

</div>

> [@mocalvao](#):
>
> (1) how can I make it work with an array for the first argument?

The problem happens because Julia is trying to broadcast over `cosmo` as if it were some kind of array or other container (that’s the default behavior of broadcasting). To tell Julia to treat `cosmo` as a scalar, you can do:

```julia
E_Hubble.(z, Ref(cosmo))

```

where the `Ref` type acts as an instruction to treat its argument as a scalar.

To tell Julia to treat _all_ `Cosmo_model` instances as scalars in broadcasting, you can do:

```julia
Base.broadcastable(s::Cosmo_model) = Ref(s)

```

and then `E_Hubble.(z, cosmo)` will just work. In other words, this tells Julia that any `Cosmo_model` should always be wrapped in a `Ref` (and thus treated as a scalar) automatically when broadcasting.

> [@mocalvao](#):
>
> (2) is the general way I have coded the struct and the function above the best one, under all aspects, including performance? Should I really use the Parameters package or should I stick to Julia core? Any specific comments are very much welcome, since this is one of my first codings in Julia…

Your code looks fine, but it will be easier to read if you can [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) so that it is formatted properly.

One thing I would mention is that `struct`s in Julia are almost always written `LikeThis` instead of `Like_this`, so I would have done:

```julia
@with_kw struct CosmoModel
  ...
end

```

As for using `Parameters.jl`, it’s a really great tool, and there’s no reason not to use it if it fits your needs. One of the most important features of Julia is the fact that “core” Julia code is not _inherently_ faster or better than anything you can write in your own code or find in a package.

---

_[View the full topic](https://discourse.julialang.org/t/calling-a-function-with-2-arguments-of-type-float64-and-a-struct-via-its-dotted-version/49817)._
