From 1ddd46f2557ec1a3daf188873930d03c4123d174 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 24 Apr 2020 08:40:52 -0500 Subject: updated readme, example uses < (parse "33 * 2.5" +PARZIVAL-USER> (parse "331 / 2.5" +PARZIVAL-USER> (parse "foozball / 2.5" +PARZIVAL-USER> T #+end_src +In the last example the string ="foozball"= is not a real, so the +parse fails, resultin in nil. You can examine the third return value +to see where in the input stream the parse failed. + +** An Extended Silly Example + +The code for this example is a little long winded, so for the +impatient I present below the grand payoff. + +What we have here is a natural language calculator. It computes +addition, subtraction, multipication, and division with all the +convenience of typing out numbers without the cumbersome use of +digits! + +Here is a REPL session + +#+BEGIN_SRC + +PARZIVAL-NUMBERS> (natural-language-calc) +Hello! And Welcome To the Super Practical Natural Language Calculator! + +Type quit to quit + +> one hundred minus eight +EQUALS ninety-two + +> twenty-nine plus four hundred seventy-seven +EQUALS five hundred six + +> twenty over four +EQUALS five + +> twenty-one times sixteen +EQUALS three hundred thirty-six + +> four thousand nine hundred fifty-five times two hundred seventeen +EQUALS one million seventy-five thousand two hundred thirty-five + +> quit + +"OK" + +PARZIVAL-NUMBERS> +#+END_SRC + +(ta-dah) + +** the code + + +#+BEGIN_SRC lisp + +(defpackage :parzival-numbers + (:use :cl :parzival)) + +(in-package :parzival-numbers) + +(defun < ") + (loop named goof-calc + for line = (read-line) + do + (if (equal line "quit") + (return-from goof-calc "OK") + (let ((parsed (parse (string-downcase line) " parsed) + (format t "No no no.. all wrong...~%> ")))))) + + +#+END_SRC + ** [0/4] To Do 1) [ ] Signal Conditions on Parse Failures from =parse= function diff --git a/examples/numbers.lisp b/examples/numbers.lisp index f6b1994..d1fb30f 100644 --- a/examples/numbers.lisp +++ b/examples/numbers.lisp @@ -1,13 +1,13 @@ -(defpackage "parzival-numbers" +(defpackage :parzival-numbers (:use :cl :parzival)) -(in-package "parzival-numbers") +(in-package :parzival-numbers) (defun <