Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
tutorials:beginner:designators [2016/01/22 15:38] – [Defining inference rules for designators] gkazhoya | tutorials:beginner:designators [2016/03/04 14:09] – gkazhoya | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Creating action designators for the turtlesim | + | ====== Creating action designators for the TurtleSim |
**Description: | **Description: | ||
Line 22: | Line 22: | ||
<code lisp> | <code lisp> | ||
- | (defparameter spy-location (make-designator | + | (defparameter spy-location (make-designator |
</ | </ | ||
(Do not add this code to your tutorial files, it is meant simply for illustration here.) | (Do not add this code to your tutorial files, it is meant simply for illustration here.) | ||
- | This line of code creates a location designator ('' | + | This line of code creates a location designator ('' |
<code lisp> | <code lisp> | ||
Line 77: | Line 77: | ||
==== Creating an action designator ==== | ==== Creating an action designator ==== | ||
- | Let's try to create an action designator in the repl command line: | + | Let's try to create an action designator in the REPL command line: |
<code lisp> | <code lisp> | ||
- | TUT> (defparameter my-desig (make-designator | + | TUT> (defparameter my-desig (make-designator |
MY-DESIG | MY-DESIG | ||
TUT> (desig-prop-value my-desig :radius) | TUT> (desig-prop-value my-desig :radius) | ||
Line 101: | Line 101: | ||
This rather obscure error message is CRAM's way of telling you there are no rules in place to resolve this designator, so let's try to provide a few such rules. | This rather obscure error message is CRAM's way of telling you there are no rules in place to resolve this designator, so let's try to provide a few such rules. | ||
+ | In case you were wondering why we use keywords in designator properties, that is because we would like to be able to specify rules to resolve designators in one package and create designators that are resolved through these rules in a different package. To avoid naming clashes between packages and huge import lists, we simply define all designator properties in the '' | ||
==== Defining inference rules for designators ==== | ==== Defining inference rules for designators ==== | ||
Line 128: | Line 129: | ||
(desig-prop ?desig (:shape :square)) | (desig-prop ?desig (:shape :square)) | ||
(desig-prop ?desig (:radius ?radius)) | (desig-prop ?desig (:radius ?radius)) | ||
- | (lisp-fun make-turtle-shape :radius ?radius :edges 4 ?action)) | + | (lisp-fun make-turtle-shape :radius ?radius :edges 4 ?action)) |
;; pentagon | ;; pentagon | ||
Line 135: | Line 136: | ||
(desig-prop ?desig (:shape :pentagon)) | (desig-prop ?desig (:shape :pentagon)) | ||
(desig-prop ?desig (:radius ?radius)) | (desig-prop ?desig (:radius ?radius)) | ||
- | (lisp-fun make-turtle-shape :radius ?radius :edges 5 ?action)) | + | (lisp-fun make-turtle-shape :radius ?radius :edges 5 ?action)) |
;; hexagon | ;; hexagon | ||
Line 142: | Line 143: | ||
(desig-prop ?desig (:shape :hexagon)) | (desig-prop ?desig (:shape :hexagon)) | ||
(desig-prop ?desig (:radius ?radius)) | (desig-prop ?desig (:radius ?radius)) | ||
- | (lisp-fun make-turtle-shape :radius ?radius :edges 6 ?action))) | + | (lisp-fun make-turtle-shape :radius ?radius :edges 6 ?action))) |
</ | </ | ||
Line 174: | Line 175: | ||
Prolog' | Prolog' | ||
- | For the example rule we've selected, Prolog looks at the designator and asks "does it contain a key-value pair that is (:type : | + | For the example rule we've selected, Prolog looks at the designator and asks "does it contain a key-value pair that is '' |
+ | |||
+ | If all of the above body rules are true (or can be executed sucessfully) then the head is itself evaluated, and what it does is glue the newly created ''? | ||
- | If all of the above body rules are true (or can be executed sucessfully) then the head is itself run, and what it does is glue the newly created ?action, the object containing the concrete values, to the designator ?desig. Or in more concrete terms, it defines what the value of the action-desig predicate is if applied to ? | + | If in any step of the inference Prolog stumbles upon '' |
- | For this tutorial, the inference is very simple: in fact, it is just a conditional switch based on the shape parameter which translates a name like ' | + | For this tutorial, the inference is very simple: in fact, it is just a conditional switch based on the shape parameter which translates a name like '' |
- | Reload the tutorial package in roslisp_repl. This will also load the newly defined inference rules. | + | Reload the tutorial package in '' |
- | Let's try to create, then reference a designator in the repl command line again: | + | Let's try to create, then reference a designator in the REPL command line again: |
<code lisp> | <code lisp> | ||
- | TUT> (defparameter | + | TUT> (defparameter |
- | MYDESIG | + | MY-DESIG-2 |
- | TUT> (reference | + | TUT> (reference |
- | (SHAPE # | + | (DRAW-SHAPE # |
</ | </ | ||