# Exercise: Safe Access by Branching on the Bool
#
# `map.get` returns ( Value Bool ). The Bool tells you whether the
# key was found. Use `if` to choose between using the looked-up
# value and falling back to a default.
#
# Pattern:
#   my-map "key" map.get      # ( Value Bool )
#   [ ... ]                   # found: Value is on the stack
#   [ drop "default" ]        # missing: drop placeholder, push default
#   if
#
# Your task: Implement `get-or`, which looks up Key in Map and
# returns Value if found, or Default otherwise.
#
# Hint: the arguments are ( Map Key Default ) but `map.get` wants
# ( Map Key ). Rearrange with `rot rot` so Default is buried below
# Map and Key, then branch on the Bool.
#
# When done, delete the marker line below.

# I AM NOT DONE

: make-test-map ( -- Map )
    map.make
    "name" "Bob" map.set
;

: get-or ( Map String String -- String )
    # Stack: Map Key Default
    # Your code here (placeholder always returns Default)
    nip nip
;

: test-get-existing ( -- )
    make-test-map
    "name" "Unknown" get-or

    # Do not edit below this line
    "Bob" string.equal? test.assert
;

: test-get-missing ( -- )
    make-test-map
    "age" "Unknown" get-or

    # Do not edit below this line
    "Unknown" string.equal? test.assert
;
