# What does this code do?

**URL:** <https://discourse.julialang.org/t/what-does-this-code-do/89266>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 26, 2022, 1:50am UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266 "2022-10-26T01:50:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [October 26, 2022, 1:50am UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/1 "2022-10-26T01:50:44Z")

</div>

I found this code recently. Does anybody know what it’s supposed to do?

```julia
(zip()...,)

```

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [October 26, 2022, 2:02am UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/2 "2022-10-26T02:02:14Z")

</div>

Wow, interesting find. For folks who try to run this code: `Ctrl-C` is your friend.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [October 26, 2022, 2:07am UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/3 "2022-10-26T02:07:10Z")

</div>

> <https://github.com/JuliaLang/julia/issues/43821>
>
> \`\`\`jl
> for z in zip()
> @show z
> end
> \`\`\`
> is an infinite loop, printing \`z =… ()\` over and over.
> 
> Arguably, it should execute once with \`z = ()\`, or maybe throw an error, or maybe execute zero times (like Python), but in any case the current behavior seems bad.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [October 26, 2022, 3:49am UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/4 "2022-10-26T03:49:13Z")

</div>

Good to know that this behavior is desired!

I spent some hours frustratedly trying to figure out why my program was just hanging, to find that it was because of this.

This is what I was doing. I swear I copypasted it from somewhere, but I can’t find it now. It converts `Dict`s to `NamedTuple`s:

```julia
mydict = Dict(:a=>1, :b=>2)
nt = (; zip(zip(mydict...)...)...)

```

Works fine until `mydict` is empty. That part of the code was stable for a while and wasn’t part of the execution chain I was actively working on (it was part of a custom `Base.show`), so it took a while for me to suspect it. Of course, in other places I used the more terse and reasonable:

```julia
nt = (; mydict...)

```

but for `show` performance didn’t matter and it worked fine so I didn’t revisit it, until I ran into this edge case long after originally writing it.

It seems like a fun easter egg, something to give to people you don’t like so their programs nuke when they least expect it.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 26, 2022, 4:22am UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/5 "2022-10-26T04:22:42Z")

</div>

> [@uniment](#):
>
> that this behavior is desired!

I disagree and clearly at least one other person disagree @stevengj

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [October 26, 2022, 9:37am UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/6 "2022-10-26T09:37:10Z")

</div>

I probably deserved to be in debugging hell for writing such horrid code to begin with. Some form of cosmic coding karma.

I was thinking it could make a nice interview question to stump new hires. Is crash prevention really worth eliminating a possible interview question?

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [October 26, 2022, 1:44pm UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/7 "2022-10-26T13:44:29Z")

</div>

> [@uniment](#):
>
> ```julia
> nt = (; mydict...)
> 
> ```

You can just use the `NamedTuple` constructor:

```julia
julia> NamedTuple(Dict(:a => 1, :b => 2))
(a = 1, b = 2)

julia> NamedTuple(Dict())
NamedTuple()

```

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [October 26, 2022, 8:53pm UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/8 "2022-10-26T20:53:31Z")

</div>

Wow, it looks like I even [knew this already](https://discourse.julialang.org/t/destructuring-syntax-in-julia-1-7/68236/56) but I forgot! Funny how that works.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [October 27, 2022, 6:51pm UTC](https://discourse.julialang.org/t/what-does-this-code-do/89266/9 "2022-10-27T18:51:40Z")

</div>

Is this considered idiomatic?

```julia
for zip! in zip() zip, zip, zip, zip!, zip!, zip! end

```

or is this better:

```julia
for (zip!, zip!!) in zip(zip(), zip(zip())) zip, zip, zip, zip!, zip!, zip!, zip!!, zip!!, zip!! end

```

thinking of putting it into the `catch` branch of `try...catch` statements.
