From ce63f3b1a1a735c365996ebf47b59a19353fcc4e Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Wed, 5 Jun 2013 02:31:04 -0400 Subject: [PATCH] Add a placeholder tutorial section on errors --- docs/sphinx/tutorial/errors.rst | 70 +++++++++++++++++++++++++++++++++ docs/sphinx/tutorial/index.rst | 1 + examples/fib.dyna | 4 +- misc/ghc-bootstrap.sh | 2 +- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 docs/sphinx/tutorial/errors.rst diff --git a/docs/sphinx/tutorial/errors.rst b/docs/sphinx/tutorial/errors.rst new file mode 100644 index 0000000..d3c01f8 --- /dev/null +++ b/docs/sphinx/tutorial/errors.rst @@ -0,0 +1,70 @@ +.. Tutorial chapter on errors + This file is enumerated in the toctree directive of /tutorial/index.rst + +.. index:: + double: tutorial; errors + +When Things Go Wrong +#################### + +Impossible Requests +=================== + +What happens if a Dyna program attempts to divide by zero, as in:: + + a += 1 / b. + b += 0. + +If this is the entirety of the program and no changes are forthcoming +(*e.g.*, we are not in interactive mode) then the semantics of this program +include division by zero, and so must be an error. What happens when we +attempt to run it? Our interpreter produces a chart with an annotation:: + + Charts + ============ + a/0 + ================= + + + b/0 + ================= + b := 0 + + + Errors + ============ + because b is 0: + division by zero + +This last ``Errors`` display indicates that the answers available in the +``Charts`` section is not reliable. + +.. caution:: Any error is potentially global! While it might be possible + for some programs to more accurately track errors, currently our + implementation does not. The net effect of this is that if ever the + interpreter produces an ``Errors`` section, then the entire chart must be + considered suspect. + +Non-Termination +=============== + +As mentioned before, Dyna2 currently uses *agenda-driven semi-naive forward +chaining* for its reasoning. This algorithm has several excellent +theoretical properties, but suffers from a potentially show-stopping +problem: *it might not stop*. + +A Dyna program which includes a definition of the Fibonacci numbers :: + + fib(1) += 1. + fib(2) += 1. + fib(X) += fib(X-1) + fib(X-2). + +will compile and be accepted by the interpreter, but will attempt to prove +a ``fib`` item for every positive natural number! Clearly, this task is +going to take a while. + +If your program goes away for longer than you expect, it is entirely +possible that it is caught in such an infinite loop. In that case, you may +send it a ``SIGINT`` by hitting Control-C. The interpreter will then print +out the chart as far as it had determined it. If this is far bigger than +expected, your program probably has a productive infinite loop. diff --git a/docs/sphinx/tutorial/index.rst b/docs/sphinx/tutorial/index.rst index bfd017d..4a601e6 100644 --- a/docs/sphinx/tutorial/index.rst +++ b/docs/sphinx/tutorial/index.rst @@ -8,3 +8,4 @@ Tutorial hello dijkstra + errors diff --git a/examples/fib.dyna b/examples/fib.dyna index aad92b8..413022a 100644 --- a/examples/fib.dyna +++ b/examples/fib.dyna @@ -1,5 +1,5 @@ % Fibonacci numbers -f(1) += 1+0 . -f(2) += 1+0 . +f(1) += 1 . +f(2) += 1 . f(X) += f(X-1) + f(X-2). diff --git a/misc/ghc-bootstrap.sh b/misc/ghc-bootstrap.sh index d44a64b..c7b0725 100644 --- a/misc/ghc-bootstrap.sh +++ b/misc/ghc-bootstrap.sh @@ -61,7 +61,7 @@ case $CMD in run) export PREFIX=$HPATH - $@ + "$@" ;; reinstall) -- 2.50.1