# Exercise: list.fold - Reduce to Single Value
#
# `list.fold` combines all elements into one value.
# Also known as "reduce" in other languages.
#
# Stack effect: ( List Acc [ Acc T -- Acc ] -- Acc )
#
# What your quotation sees on each step:
#   ( ... Acc T )    # T = current element, on TOP
#                    # Acc = accumulator-so-far, BELOW
# It must produce a new Acc and leave nothing else behind.
#
# Example:
#   "apple banana cherry" " " string.split "" [ string.concat ] list.fold
#   # Result: "applebananacherry"
#   # On each step `Acc T string.concat` produces Acc ++ T.
#
# HIGHER-ORDER PATTERN:
# fold is the most general list operation. You can implement
# map and filter in terms of fold! It takes:
#   - An initial accumulator value
#   - A quotation that combines the accumulator (below) with the
#     current element (on top), returning the new accumulator
#
# Your task: Concatenate all words with dashes between them.
# When done, delete the marker line below.

# I AM NOT DONE

: join-with-dash ( Variant -- String )
    # Your code here.
    # Hint: fold starting with an empty accumulator. On each
    # step, insert a dash before appending the next word — except
    # when the accumulator is still empty (the very first word).
    drop ""
;

: test-fold ( -- )
    "one two three" " " string.split join-with-dash
    # Do not edit below this line
    "one-two-three" string.equal? test.assert
;
