Skip to content
Browse files

Add FLUID-LET.

  • Loading branch information...
1 parent 0a3c7c8 commit 498bae0dea8ced7ad9e2f350df07d8561e54f296 @manuel committed Mar 20, 2012
Showing with 17 additions and 0 deletions.
  1. +6 −0 standard.virtua
  2. +11 −0 test.virtua
View
6 standard.virtua
@@ -159,6 +159,12 @@
(eval (list* (setter (eval cmb env)) value args) env))
(eval (list $set! place value) env)))
+(defmacro fluid-let ((name value) . body) env
+ (let ((saved-value (eval name env)))
+ (eval (list set! name value) env)
+ (unwind-protect (eval (list* begin body) env)
+ (eval (list set! name saved-value) env))))
+
(defun setter (obj) (get-slot obj "setter"))
(defun set-setter! (obj setter) (set-slot! obj "setter" setter))
(set-setter! js-global (lambda (val name) (set-js-global! name val))) ; erm
View
11 test.virtua
@@ -159,6 +159,17 @@
(assert (= "foobar" (strcat "foo" "bar")))
+(scope
+ (def x 1)
+ (fluid-let (x 2)
+ (assert (= x 2)))
+ (assert (= x 1))
+ (block exit
+ (fluid-let (x 3)
+ (assert (= x 3))
+ (return-from exit)))
+ (assert (= x 1)))
+
;;;; Options
(assert (= 12 (if-option (name (option 12)) name 13)))

0 comments on commit 498bae0

Please sign in to comment.
Something went wrong with that request. Please try again.