# Exercise: Checking File Existence
#
# `file.exists?` checks whether a path resolves to a real file.
#
# Stack effect: ( path -- Bool )
#   Bool : true if the file exists and can be stat'd, false otherwise
#
# This is the cheap pre-flight check before a `file.slurp` or any
# other op that would otherwise return a status flag you have to
# handle. It's also useful for "if config exists, load it; otherwise
# use defaults" patterns.
#
# Note: `file.slurp` already returns its own status Bool, so a
# pre-`file.exists?` check is *not* required for safety. Use it when
# the *meaning* of present-vs-absent is part of your control flow,
# not just to avoid an error.
#
# Your task: Write a word that takes a path and returns "yes" if
# the file exists, "no" if it doesn't. The two assertions below
# probe both branches: one against the fixture you used in 01, and
# one against a path that's guaranteed not to exist.
#
# Run seqlings from the project root so the relative fixture path
# resolves.
#
# When done, delete the marker line below.

# I AM NOT DONE

: present? ( String -- String )
    # Branch on file.exists? and push "yes" or "no".
    drop ""
;

: test-exists-yes ( -- )
    "exercises/20-files/data/greeting.txt" present?
    # Do not edit below this line
    "yes" string.equal? test.assert
;

: test-exists-no ( -- )
    "/no/such/path/seqlings-bogus-9c7f.txt" present?
    # Do not edit below this line
    "no" string.equal? test.assert
;
