# Exercise: list.filter - Select Elements
#
# `list.filter` keeps only elements where the quotation returns true.
#
# Stack effect: ( Variant Quotation -- Variant )
#
# Example:
#   "apple banana cherry" " " string.split [ string.length 5 i.> ] list.filter
#   # Keeps only "banana" and "cherry" (length > 5)
#
# HIGHER-ORDER PATTERN:
# filter separates the WHAT (predicate) from the HOW (iteration).
# The quotation is a predicate - it must return a boolean (0 or non-zero).
#
# Your task: Keep only words longer than 4 characters.
# When done, delete the marker line below.

# I AM NOT DONE

: long-words-only ( Variant -- Variant )
    # Your code here. Keep only the elements whose length is
    # greater than four.
    drop "x" " " string.split
;

: test-filter ( -- )
    "cat dog elephant mouse" " " string.split long-words-only
    # Do not edit below this line
    dup list.length 2 test.assert-eq
    dup 0 variant.field-at "elephant" string.equal? test.assert
    1 variant.field-at "mouse" string.equal? test.assert
;
