What is correct method to determine if a map key exists?

Started by cssyphus, May 17, 2024, 08:45:30 AM

Previous topic - Next topic

cssyphus

What is the correct way to determine if a map element exists?

For example, the isDefined() test generates an "Array subscript out of bounds" error:

_Lst = `Ann,1` :@TAB: `Bob,2` :@TAB: `Carl,3`
_map = MapCreate(_Lst)
if isDefined(_map[`Bob`])
message(`Bob is in pos`, _map[`Bob`])
endif
if isDefined(_map[`Fred`])
message(`Fred is in pos`, _map[`Fred`])
endif


td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

cssyphus

I'm going with: "that wasn't in MY copy of the help file when I looked at it yesterday..." But it's there now. Spooky. Mandela effect?

Thanks Tony.

Man, if I had an extra minute of life for every hour I've spent searching for something that is right under my nose (and often not finding it)... I'd live forever.

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

I appear to be nearly blind to my own typos.  It's a bummer.
The mind is everything; What you think, you become.

snowsnowsnow

Quote from: td on May 18, 2024, 03:37:37 PMMy wife calls it refrigerator blindness...

I first heard that term in a comedy routine by Rita Rudner.

She's great.  I love her.