Skip to content

Commit

Permalink
Don't change the values in promise closures from continuations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramarren committed Oct 23, 2008
1 parent f72aa0a commit 5e8048d
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions combinators.lisp
Expand Up @@ -69,19 +69,21 @@
"Combinator: one alternative from two parsers"
`(delay
(let ((parser1-promise ,parser1-promise)
(parser2-promise ,parser2-promise)
(is-unread t))
(parser2-promise ,parser2-promise))
#'(lambda (inp)
(make-instance 'parse-result
:continuation
#'(lambda ()
(when is-unread
(setf is-unread nil)
(let ((result (funcall (execute-choice inp
(force parser1-promise)
(force parser2-promise)))))
(setf parser1-promise nil parser2-promise nil)
result))))))))
(let ((parser1-promise parser1-promise)
(parser2-promise parser2-promise)
(is-unread t))
(make-instance 'parse-result
:continuation
#'(lambda ()
(when is-unread
(setf is-unread nil)
(let ((result (funcall (execute-choice inp
(force parser1-promise)
(force parser2-promise)))))
(setf parser1-promise nil parser2-promise nil)
result)))))))))

(defmacro choices (&rest parser-promise-list)
"Combinator: all alternatives from multiple parsers"
Expand All @@ -93,17 +95,18 @@
(defmacro choices1 (&rest parser-promise-list)
"Combinator: one alternative from multiple parsers"
`(delay
(let ((parser-promise-list (list ,@parser-promise-list))
(is-unread t))
(let ((parser-promise-list (list ,@parser-promise-list)))
#'(lambda (inp)
(make-instance 'parse-result
:continuation
#'(lambda ()
(when is-unread
(setf is-unread t)
(iter (for p in parser-promise-list)
(for result = (next-result (funcall (force p) inp)))
(finding (make-instance 'parse-result
:top-results (list (car result-list)))
such-that result)
(finally (setf parser-promise-list nil))))))))))
(let ((parser-promise-list parser-promise-list)
(is-unread t))
(make-instance 'parse-result
:continuation
#'(lambda ()
(when is-unread
(setf is-unread t)
(iter (for p in parser-promise-list)
(for result = (next-result (funcall (force p) inp)))
(finding (make-instance 'parse-result
:top-results (list (car result-list)))
such-that result)
(finally (setf parser-promise-list nil)))))))))))

0 comments on commit 5e8048d

Please sign in to comment.