# -*- wisp -*-
exec guile -L $(dirname $(dirname $(realpath "$0"))) --language=wisp -e '(@@ (examples with) main)' -s "$0" "$@"
;; A cleaner way to implement this might be using dynamic-wind.
;; FIXME: This might not be continuation-safe and might break if the
;; code in the with block uses dynamic-wind. Check whether it’s safe
;; and fix it if not.
define-module : examples with
import : oop goops
define : enter thing
define : exit thing
syntax-rules : as
: _ thing as name thunk ...
: name : enter thing
res : begin thunk ...
define-method : exit (thing <port>)
. "Ensure that a port is always closed at the end of the with-block."
define : main args
with (open-file "with.w" "r") as port
format #t "~a\n" : read port