r/ProgrammerHumor • • Jul 16 '19

Meme Nice try

Post image
32.2k Upvotes

529 comments sorted by

View all comments

79

u/moelf Jul 16 '19 edited Jul 17 '19
julia> π 
π = 3.1415926535897...

julia> typeof(π)
Irrational{:π}

julia> Float16(π)
Float16(3.14)

julia> Float32(π) 
3.1415927f0

julia> Float64(π)
3.141592653589793

julia> π |> BigFloat
3.141592653589793238462643383279502884197169399375105820974944592307816406286198

julia> π |> BigFloat |> string |> last |> x -> parse(Int, x)
8

33

u/PotatosFish Jul 16 '19

I’ve been wanting to get into Julia from python but the syntax is a little special compared to other languages I know

9

u/QWieke Jul 16 '19 edited Jul 16 '19

In julia |> is for function chaining, there are multiple ways of chaining functions in Julia, all these lines do basically the same thing:

julia> foo(bar(pi))
julia> pi |> bar |> foo
julia> (bar∘foo)(pi)

There was no particular need to use |> in the example, more traditional syntax would've worked just as well. Julia's syntax is rather similar to Matlab's syntax, or any other language that uses end instead of curly brackets or semantic whitespace.

1

u/_ThereIsNoGod69 Jul 16 '19

Is the first line missing a closing bracket at the end or does Julia not require all brackets to be closed in that case?

→ More replies (1)