;;; -*- Mode: Lisp -*- ;;; ;;; Answers to exercises in chapter 1 of Nilsson's Principles of A.I. ;;; Copyright (C) 2021 Gene Michael Stover (gene@acm.org) ;;; ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see . ;;; ;;; Documentation is at http://cybertiggyr.com/nilsson_principles/00readme.html ;;; (defpackage "NILSON_PRINCIPLES.EX_01_03" (:use "COMMON-LISP")) (in-package "NILSON_PRINCIPLES.EX_01_03") (defun random-elt (x &aux r) (setq r (random (length x))) (elt x r)) (defun sentence () (append (dnp) (vp))) (defun vp () (append (v) (dnp))) (defun pp () (append (p) (dnp))) (defun p () (random-elt '(("of") ("from") ("in") ("into") ("by") ("with")))) (defun v () (random-elt '(("approves") ("creates") ("loves") ("distracts") ("worries") ("wonders") ("fixes") ("breaks") ("botches") ("repairs") ("observes") ("oversees")))) (defun dnp () (funcall (random-elt (list (lambda () (append (det) (np))) (lambda () (append (dnp) (pp))))))) (defun np () (funcall (random-elt (list (lambda () (append (a) (np))) (lambda () (n)))))) (defun a () (random-elt '(("new") ("ancient") ("red") ("green") ("mauve") ("feline") ("lionine") ("stinky") ("aromatic") ("electric") ("recreational")))) (defun n () (random-elt '(("president") ("company") ("sale") ("human") ("cat") ("dog") ("humming bird") ("brown bear") ("black bear") ("rocket") ("couch") ("chaise lounge") ("chair") ("electric car") ("computer") ("android") ("robot")))) (defun det () (random-elt '(("the") ("this") ("that") ("a") ("any") ("an") ("some")))) ;;; end of file