# Exercise: Writing Higher-Order Words
#
# Now YOU write a higher-order word - one that takes a quotation!
#
# HIGHER-ORDER INSIGHT:
# This exercise crosses a threshold: you're not just using
# higher-order programming, you're creating higher-order abstractions.
#
# Writing words that accept quotations is a powerful technique
# for building flexible, reusable code.
#
# Your task: Define `apply-twice` that runs a quotation 2 times.
#
# Example:
#   5 [ 1 i.+ ] apply-twice   # 5→6→7, result: 7
#   3 [ dup i.* ] apply-twice  # 3→9→81, result: 81
#
# Hint: each `call` consumes the quotation it executes.
# When done, delete the marker line below.

# I AM NOT DONE

: apply-twice ( Int [ Int -- Int ] -- Int )
    # Your code here
    # Takes a quotation and applies it twice
    drop
;

: test-higher-order ( -- )
    5 [ 3 i.+ ] apply-twice
    # Do not edit below this line
    11 test.assert-eq   # 5 + 3 + 3 = 11

    2 [ dup i.* ] apply-twice
    16 test.assert-eq   # 2→4→16
;
