Sorted Key Dictionary
#8
(04-13-2023, 07:37 PM)bplus Wrote: Ah this is way more fun when I have a practical application for Dictionary.

...

A great use case for a dictionary: country code lookup.

Just for the giggles, here's one silly (but interesting to me) use case for a dictionary (very rudimentary capability in BAM).  Kind of simulating a "one-liner switch" statement:


Code: (Select All)
INIT:

  _initaudio

  _mapset("CARROT", 1)
  _mapset("CORN", 2)
  _mapset("POTATO", 3)

MAIN_PROGRAM:

  getselection:
    input "Search for recipes: enter one ingredient:", selection$
    selection$ = ucase$(selection$)
    if _mapget(selection$) = "" then beep : print "sorry, no recipes for " + selection$ : goto getselection

  on _mapget(selection$) gosub CARROT, CORN, POTATO

  goto getselection

  end

SUBROUTINES:

  CARROT:
    print "setup special processing for carrot-related recipes and info"
    RETURN

  CORN:
    print "setup special processing for corn-related recipes and info"
    RETURN

  POTATO:
    print "setup special processing for potato-relatd recipes and info"
    RETURN
Reply


Messages In This Thread
Sorted Key Dictionary - by bplus - 04-12-2023, 06:52 PM
RE: Sorted Key Dictionary - by madscijr - 04-12-2023, 07:15 PM
RE: Sorted Key Dictionary - by TempodiBasic - 04-12-2023, 11:14 PM
RE: Sorted Key Dictionary - by bplus - 04-13-2023, 07:37 PM
RE: Sorted Key Dictionary - by CharlieJV - 04-15-2023, 03:42 PM
RE: Sorted Key Dictionary - by TempodiBasic - 04-13-2023, 08:39 PM
RE: Sorted Key Dictionary - by bplus - 04-13-2023, 09:50 PM
RE: Sorted Key Dictionary - by TempodiBasic - 04-15-2023, 10:48 AM
RE: Sorted Key Dictionary - by bplus - 04-15-2023, 04:55 PM
RE: Sorted Key Dictionary - by CharlieJV - 04-15-2023, 07:11 PM



Users browsing this thread: 2 Guest(s)