You probably did this:

julia> x = rand(3)
3-element Array{Float64,1}:
 0.203537 
 0.0976039
 0.425243 

julia> sum = 5   # you just borked sum
5

julia> sum(x)
ERROR: type: apply: expected Function, got Int64

But notice sum is still there:

julia> Base.sum(x)
0.7263840892398132

julia> sum = Base.sum
sum (generic function with 13 methods)

julia> sum(x)
0.7263840892398132


The ability to treat a function as a variable is very powerful: you can pass 
functions as arguments to other functions.

--Tim

On Monday, May 18, 2015 08:37:54 AM James Byars wrote:
> Thank you. I said this in the post below, but is this an issue with Julia
> going forward? The need to restart.
> 
> On Monday, May 18, 2015 at 10:50:28 AM UTC-4, Kristoffer Carlsson wrote:
> > This works for me, both in Julia 0.3 and 0.4
> > 
> > julia> function fib_sum_2(x,y,z)
> > 
> >            sum(x:x:z) + sum(y:y:z) - sum(lcm(x,y):lcm(x,y):z)
> >        
> >        end
> > 
> > fib_sum_2 (generic function with 1 method)
> > 
> > 
> > julia> fib_sum_2(3,5,999)
> > 233168
> > 
> > What happens if you restart Julia and try again?
> > 
> > On Monday, May 18, 2015 at 4:34:11 PM UTC+2, James Byars wrote:
> >> Hello all,
> >> 
> >> I am an education doctoral student who is a self-taught stats and
> >> programming person. My primary coding and stats experience is with R. I
> >> have started to attempt Julia and was using the Project Euler questions
> >> as
> >> a way to teach myself the language structure, types, and specifying
> >> functions. I have been really drawn to Julia because of all the great
> >> conversations about the language on the YouTube channel. There have been
> >> several great repositories that share coding examples for each of the
> >> problems (although Project Euler wants everybody to do it on their own)
> >> which have been tremendously helpful.
> >> 
> >> One of the proposed solutions for Problem #1 have this structure:
> >> println(sum(3:3:999) + sum(5:5:999) - sum(15:15:999))
> >> 
> >> I am trying to make a function of this type of problem so I am not
> >> bounded by specifying each number every time. So I adapted the solution
> >> to
> >> the following format:
> >> 
> >> *function fib_sum_2(x,y,z)*
> >> *    sum(x:x:z) + sum(y:y:z) - sum(lcm(x,y):lcm(x,y):z)*
> >> *end*
> >> 
> >> However, when I try to run the function (fib_sum_2(3,5,999)) I get the
> >> following error:
> >> 
> >> *type: fib_sum_2: in apply, expected Function, got Int64
> >> while loading In[140], in expression starting on line 1
> >> 
> >>  in fib_sum_2 at In[137]:2*
> >> 
> >> I did attempt to google this problem, but still could not find a source
> >> that really explained the problem. I understand that this is a really
> >> newbie question and thank you to everyone for their patience and any
> >> assistance. If anybody can correct my error or provide resources that
> >> might help me with future Euler Project problems that would be great. I
> >> feel that I am missing something terribly easy with Julia, but thank you
> >> all for any help. Also, I am using IJulia for reference. If I have
> >> posted this question in error, can anybody direct me to the right forum?
> >> 
> >> 
> >> With Regards,
> >> 
> >> 
> >> James

Reply via email to