# A most harrowing collection of Julia WATs

**URL:** https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323
**Category:** General Usage
**Tags:** wat
**Created:** [March 2, 2022, 6:15pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323 "2022-03-02T18:15:32Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)
#### Post date: [March 2, 2022, 6:15pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/1 "2022-03-02T18:15:33Z")

</div>

Hello all! 👋  
I’ve been collecting a few of the most cursed corner cases of Julia [WATs](https://www.destroyallsoftware.com/talks/wat) that [I know of here](https://miguelraz.github.io/blog/juliawats/) (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
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.

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [March 2, 2022, 6:26pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/2 "2022-03-02T18:26:27Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [March 2, 2022, 6:30pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/3 "2022-03-02T18:30:28Z")

</div>

> [@miguelraz](#):
>
> …wat.

Interestingly, syntax highlighting makes it hard to understand the wat

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [March 2, 2022, 8:14pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/4 "2022-03-02T20:14:52Z")

</div>

See also Bogumił Kamiński’s

[Pitfalls of macro invocation in Julia](https://bkamins.github.io/julialang/2022/01/14/macros.html)

```julia
julia> macro m(args...)
           show(args)
       end
@m (macro with 1 method)

julia> @m 1 + 1
(:(1 + 1),)
julia> @m 1+1
(:(1 + 1),)
julia> @m 1 +1
(1, 1)

```

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [March 3, 2022, 4:23am UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/5 "2022-03-03T04:23:56Z")

</div>

I always thought allowing things like `2x` (instead of requiring `2*x`) was just setting up things to fail in  
unexpected ways. Wat!?

---

<div class="post-metadata">

### Author: ![Philogicatician](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philogicatician/32/34172_2.png) [@Philogicatician](https://discourse.julialang.org/u/Philogicatician)
#### Post date: [March 3, 2022, 7:34am UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/6 "2022-03-03T07:34:19Z")

</div>

One of your WATs isn’t quite true:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/f/7f1e24b877c5b332a41a3a3ace6bcf55fc8f0851.png)

---

<div class="post-metadata">

### Author: ![Philogicatician](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philogicatician/32/34172_2.png) [@Philogicatician](https://discourse.julialang.org/u/Philogicatician)
#### Post date: [March 3, 2022, 7:37am UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/7 "2022-03-03T07:37:50Z")

</div>

However, the other example of “Shadowing” does reproduce the error shown that Kristopher Carlsson pointed out:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/2/f29e13f8b9db87e00c4d8ef50dcc940e5327a5f1.png)

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [March 3, 2022, 7:50am UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/8 "2022-03-03T07:50:55Z")

</div>

Probably because you already used `-` in your session

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [March 3, 2022, 10:54am UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/9 "2022-03-03T10:54:26Z")

</div>

One from many on [another of Bogumił Kamiński’s blog posts](https://bkamins.github.io/julialang/2021/11/12/so.html)

```julia
julia> isequal(sum([-0.0, -0.0]), sum([-0.0, -0.0], init=0.0))
false

```

---

<div class="post-metadata">

### Author: ![Philogicatician](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philogicatician/32/34172_2.png) [@Philogicatician](https://discourse.julialang.org/u/Philogicatician)
#### Post date: [March 3, 2022, 7:11pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/10 "2022-03-03T19:11:00Z")

</div>

Ah, thanks @giordano, looks like you’re right:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/6/b6537c42c65b96ac509e474e2421173a8f41940d.png)

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [March 4, 2022, 12:08pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/11 "2022-03-04T12:08:08Z")

</div>

Great collection! A couple of comments though:

- “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
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.

---

<div class="post-metadata">

### Author: ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)
#### Post date: [March 4, 2022, 12:41pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/12 "2022-03-04T12:41:01Z")

</div>

That looks perfectly fine to me, no surprise if it behaves like arrays.

---

<div class="post-metadata">

### Author: ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)
#### Post date: [March 4, 2022, 12:44pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/13 "2022-03-04T12:44:52Z")

</div>

This is well documented in `?isequal`

```julia
..
 julia> 0.0 == -0.0
 true

 julia> isequal(0.0, -0.0)
 false
..

```

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [March 4, 2022, 12:54pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/14 "2022-03-04T12:54:19Z")

</div>

Another one for the shadowing category

```julia
julia> Iterators = (map = (f, x)->f.(x).^2,)
(map = var"#1#2"(),)

julia> Iterators.map(identity, 1:5)
5-element Vector{Int64}:
  1
  4
  9
 16
 25

```

It’s a bit contrived, but actually happened to me in a different way because I accidentily pasted a compat requirement into the REPL…

---

<div class="post-metadata">

### Author: ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)
#### Post date: [March 4, 2022, 6:10pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/15 "2022-03-04T18:10:30Z")

</div>

For me it was that I thought that the anonymous function syntax was only valid using `->`, so this came as a surprise.

Looking at it, I also like it too now 😜

```julia
julia> const a = (function(x)
    # more code
    x^2
end)(2)
4

julia> const b = ((x) -> begin
    # more code
    x^2
end)(2)
4

```

It is more readable for in-place functions (although I don’t know if people use them, maybe for some initializer).

---

<div class="post-metadata">

### Author: ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)
#### Post date: [March 4, 2022, 8:06pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/16 "2022-03-04T20:06:40Z")

</div>

Thanks for the comments @tim.holy !

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.

---

<div class="post-metadata">

### Author: ![schnetter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schnetter/32/45_2.png) [@schnetter](https://discourse.julialang.org/u/schnetter)
#### Post date: [March 5, 2022, 4:42pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/17 "2022-03-05T16:42:44Z")

</div>

Miguel

This code is inefficient when called with an integer argument:

```nohighlight
function f(x)
    x += 1
    x /= 2
    return x
end

```

To make it efficient, use different names for the temporary variables:

```nohighlight
function f(x)
    y = x+1
    z = y/2
    return z
end

```

You see the source of the inefficiency with `@code_warntype`.

-erik

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [March 5, 2022, 6:54pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/18 "2022-03-05T18:54:05Z")

</div>

Infers just fine on 1.7:

```julia
julia> function f(x)
           x += 1
           x /= 2
           return x
       end
f (generic function with 1 method)

julia> @code_typed f(1)
CodeInfo(
1 ─ %1 = Base.add_int(x@_2, 1)::Int64
│ %2 = Base.sitofp(Float64, %1)::Float64
│ %3 = Base.div_float(%2, 2.0)::Float64
└── return %3
) => Float64

```

To explain: `@code_warntype` isn’t telling the whole truth here, since the optimizer can actually deal with this when lowering slots to phi nodes.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [March 5, 2022, 11:40pm UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/19 "2022-03-05T23:40:31Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

### Author: ![krasi\_sabyata](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@krasi\_sabyata](https://discourse.julialang.org/u/krasi_sabyata)
#### Post date: [March 7, 2022, 3:16am UTC](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/20 "2022-03-07T03:16:24Z")

</div>

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.

[Next page](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323.md?page=2)
