(Arne Babenhauserheide)
2016-05-12: with: use goops to allow overriding enter and exit. with: use goops to allow overriding enter and exit.
diff --git a/examples/with.w b/examples/with.w
--- a/examples/with.w
+++ b/examples/with.w
@@ -3,17 +3,23 @@
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.
+
define-module : examples with
+import : oop goops
+
; import : ice-9 rdelim
; with (open-file "with.w") as port
; display : read-line port
-define* : enter thing
- . thing
+define : enter thing
+ . thing
+define-generic enter
-define* : exit thing
- . thing
+define : exit thing
+ . thing
+define-generic exit
define-syntax with
syntax-rules : as
@@ -24,6 +30,9 @@ define-syntax with
exit thing
. res
+define-method : exit (thing <port>)
+ close-port thing
+
define : main args
with (open-file "with.w" "r") as port
format #t "~a\n" : read port