Hello all!
I’ve been collecting a few of the most cursed corner cases of Julia WATs that I know of here (WIP), but I would appreciate if people could share their own rare specimens as well.
Please ping me with your contributions and I’ll post with proper credit.
Here’s an example of what I mean by a Julia WAT:
julia> e = 9998.0
9998.0
julia> 2e
19996.0
julia> 2e+4
20000.0
julia> 2e+5 # This should be 20001.0, right?
200000.0
julia> 2e + 5 # note the spacing
20001.0
…wat.
Some of these are just unavoidable corner cases of multiple design constraints, others are an artifact of parsing being hard, but they’re all supposed to be tongue-in-cheek puzzles of our dear JuliaLang <3.
I mean, as a scientist I did not understand the point until the last line, because the 2e+4 immediately was parsed by my mind as a number in scientific notation and I did not understand the relation with the previous e or what you did mean by your first comment.
Surely there are some Julia WATs, but this seems kinda expected from any language with both floating points and implicit multiplication, is Julia the only language with these two characteristics?
“and, or on empty collections”: not spelled out, what is the WAT? Or is it really in reference to the “broadcasting shenanigans” below it?
“what is this syntax?” I’m not sure what’s wrong with it.
julia> f = function(x) x+1 end
#11 (generic function with 1 method)
julia> f(3)
4
It’s just a way to declare an anonymous function—IMO it’s an elegant syntax because it makes it very clear that what you’re doing is not assigning a name to the function.
Yes, those comments are basically TODOs that I pepper in my blogposts and as I come back to them I overwrite them - perhaps the big WIP signs should be a bit more prominent.
And although I agree with your comments on the anonymous function syntax - it definitely made me say “WAT? You can do that?” when I first saw it, so I’m guessing it’s gonna punk other people too on their first encounter.
The floating point example feels expected for me (probably not to someone who is newer to writing code) but the rest of it is very interesting! Thank you for the linked post, its helpful as I get more acquainted with the Julia programming language.