Member-only story

TIL: wrapping my head around Go’s “iota”

Tom Deneire
3 min readJan 5, 2023

TIL (“Today I learned”) are shorter, less-researched posts that I typically write to help organize my thoughts and solidify things I have learned while working. I post them here as a personal archive and of course for others to possibly benefit from.

Photo by Kelly Sikkema on Unsplash

Iota

A few days ago, I happened upon the iota identifier in Go.

I remembered seeing it before, but it’s still pretty rare, so I looked up the definition of iota in the documentation:

const iota = 0 // Untyped int.

iota is a predeclared identifier representing the untyped integer ordinal number of the current const specification in a (usually parenthesized) const declaration. It is zero-indexed.

¿Qué?

Upon reading this (several times over actually) I must confess I still didn’t really understand what iota was or did. And while the language specification is more explicit and has examples, it is not much clearer:

Within a constant declaration, the predeclared identifier iota represents successive untyped integer constants. Its value is the index of the respective ConstSpec in that constant declaration, starting at zero. It can be used to construct a set of related constants

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Tom Deneire
Tom Deneire

Written by Tom Deneire

Software engineer, technical writer, IT burnout coach @ https://tomdeneire.be/confident_coding

Responses (1)

Write a response

Thanks for this explicit illustration of iota possible usages. I was a bit like you when seing iota for the first time in code and reading the "documentation" related to it.

To be honest, while Go claims to be readable, I'm not sure the iota case…

1