MIN: How to convert atom reference to int

Joe Kaplan's icon

This feels like a silly question, but I couldn't figure out how to do it.

When you read a value from a dictionary, the type is an atom reference. If I know the value for that key is an integer, how can I convert it from an atom reference to an int? The only solution I could make work is to convert it to a string first.

dict d(args[0]);
int myInt = std::stoi(std::to_string(d["myInt"]));

I feel like there's probably a better way and I'm missing something obvious.

Appreciate any tips.

Rob Ramirez's icon

I'm sure there are other ways, but does this work:int i = atom(d["key"]);

Rob Ramirez's icon

maybe this is safer and more c++ like:

int y = static_cast<int>(static_cast<atom>(d["key"]));