Skip to content

Commit

Permalink
Rename SOME to JUST.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel committed Mar 20, 2012
1 parent 498bae0 commit 5f2b232
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
21 changes: 7 additions & 14 deletions standard.virtua
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,16 @@

;;;; Options

(definterface Option)

(defclass Option)
(defclass None (Option))

(defvar none (make-instance None))

(defclass Some (Option)
(defclass Just (Option)
(value)
(:constructor option (value)))

(defgeneric option-supplied? (option))
(defmethod option-supplied? ((n None)) #f)
(defmethod option-supplied? ((s Some)) #t)
(:constructor just (value)))

(defmacro if-option ((name option) then . else) env
(let ((o (eval option env)))
(if (option-supplied? o)
(if (instance? o Just)
(eval (list let (list (list name (.value o))) then) env)
(unless (null? else)
(eval (car else) env)))))
Expand Down Expand Up @@ -398,9 +391,9 @@

(defun call-with-handler (matcher handler thunk)
(let ((saved-stack *handler-stack*))
(set! *handler-stack* (option (make-handler-frame *handler-stack*
matcher
handler)))
(set! *handler-stack* (just (make-handler-frame *handler-stack*
matcher
handler)))
(unwind-protect ($js-try (lambda (exc)
(if (instance? exc Block-Escape)
(js-throw exc)
Expand Down
2 changes: 1 addition & 1 deletion test.virtua
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@

;;;; Options

(assert (= 12 (if-option (name (option 12)) name 13)))
(assert (= 12 (if-option (name (just 12)) name 13)))
(assert (= 13 (if-option (name none) name 13)))
(assert (= #void (if-option (name none) name)))

Expand Down

0 comments on commit 5f2b232

Please sign in to comment.