Dict should work with non-string keys

Like ints and floats.

Go spec
https://go.dev/ref/spec#Identifiers

I don’t mean that $mydict.123 should work, but

{{ range $imagewidth, $viewwidth := dict 123 456 234 567 345 678 }}
...
{{ end }}

should work.

Keys are keys.

I don’t understand what that means, or how it relates to Go identifiers. Map keys are values.

So,

The dict func currently

  • Accepts key/value pairs of string/any
  • Produces a map[string]any

What I see in the above is that we could (should?) the first bullet to accept any key value type.

But we cannot (will not?) change the second bullet to, say, map[any]any. The main reason is It would make the type incompatible with almost every API in Hugo that accepts a map.

I don’t see how you can change the first without changing the second.

Perhaps just save this as a suggestion for when breaking compatibility is on the table, e.g. v1 or v2.

It would mean that the `int´ you pass in as a key would be converted to a string.

Breaking the compability here would make the dict function incompatible with the rest of Hugo – which needs a better argument than “it should”.

It would mean that the `int´ you pass in as a key would be converted to a string.

Oh, I see. I would need them as ints. It would be confusing to convert them to strings.

Breaking the compability here would make the dict function incompatible with the rest of Hugo – which needs a better argument than “it should”.

I thought you were saying the only problem is that the change to map[any]any would be backward incompatible with other parts of the system, although everything could be changed together later. I’m unfamiliar with the parts you refer to that would break with map[any]any.

This is the only case where int keys would be useful, and I’ve only come across it recently, so if the effort is great to do it, then I don’t think it’s worth it.