does this help any?

julia> a = 1
1

julia> function inc()
        a = a+1
       end
inc (generic function with 1 method)

julia> inc()
ERROR: UndefVarError: a not defined
 in inc at none:2

julia> function inc()
        global a = a+1
       end
inc (generic function with 1 method)

julia> inc()
2

julia> inc()
3

julia> inc()
4

julia> inc()
5

julia> function make_inc(start)
        a = start
        function inc()
         a = a + 1
        end
       end
make_inc (generic function with 1 method)

julia> inc2 = make_inc(99)
inc (generic function with 1 method)

julia> inc2()
100

julia> inc2()
101

julia> inc2()
102

also http://julia.readthedocs.org/en/latest/manual/variables-and-scoping/

andrew


On Monday, 8 June 2015 11:34:47 UTC-3, [email protected] wrote:
>
> I'm currently trying to understand how functions with an exclamation mark 
> at the end work. I know the exclamation mark is just a notational point 
> however I'm currently confused at how to actually write a mutable function.
> If a = 1
>
> function add_one(a)
>     return a + 1
> end
>
> running add_one(a) twice outputs:
>     2
>     2
>
> how would I create add_one!(a) to output:
>     2
>     3
>

Reply via email to