3 ms·
It's just that the language ought not to offer other ways, and must be very terse? Otherwise it seems like many languages would qualify: julia> fact(n) = p
by improbable22 8y ago
It's just that the language ought not to offer other ways, and must be very terse? Otherwise it seems like many languages would qualify:
julia> fact(n) = prod(1:n)
That's 9 characters, shorter than q. (`julia> const Π=prod` brings it to 6, only apl is shorter.)
- geocar 8y agoBut is that how most Julia programmers will write it? I just asked someone in my office and they sent me this: function fact(n::Integer) n < 0 && return zero(n) f = one(n) for i in 2:n f *= i end return f end They seem to have google'd the result, but I'm not judging that: That might be how Julia programmers code...
- improbable22 8y agoDepends whether they cut their teeth on Matlab! I'm not sure which is faster here, often writing out the loop is a little faster but less compact.
- KenoFischer 8y agoThey're equally fast: julia> @btime fact_prod(10000) 7.833 μs (0 allocations: 0 bytes) julia> @btime fact_loop(10000) 7.908 μs (0 allocations: 0 bytes)
- deleted 8y ago[deleted]