# Turn code into function

**URL:** <https://discourse.julialang.org/t/turn-code-into-function/42147>\
**Category:** New to Julia\
**Created:** [June 27, 2020, 6:55am UTC](https://discourse.julialang.org/t/turn-code-into-function/42147 "2020-06-27T06:55:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [June 27, 2020, 7:21am UTC](https://discourse.julialang.org/t/turn-code-into-function/42147/2 "2020-06-27T07:21:37Z")

</div>

> [@colinclout12](#):
>
> In R, I don’t have to worry if the argument for the function is a scalar or a vector

Possibly, because R has no scalars, only vectors. 😉

> [@colinclout12](#):
>
> So sum doesn’t work for vectors, only for a “list” of scalars.

In your example, if you call `f` with `[2,3]`, then `x` will be a tuple `([2, 3],)`, so `sum` will sum this tuple.

> [@colinclout12](#):
>
> Perhaps this has something to do with how environments work??

No; also there are no “environments” in the R sense in Julia.

I would recommend that you start from the basics, and work through the Julia manual first. Trying to adapt R concepts to Julia will just be a source of continuous frustration.

Also, please quote your code.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

_[View the full topic](https://discourse.julialang.org/t/turn-code-into-function/42147)._
