exercises

12. cognitive models

EXERCISE 12.1

Recall the CCT description of the rule INSERT-SPACE-2 discussed in Section 12.2.2:

	(INSERT-SPACE-2
	IF (AND (TEST-GOAL insert space)
		(TEST-CURSOR %LINE %COL) )
	THEN (  (DO-KEYSTROKE 'I')
		(DO-KEYSTROKE SPACE)
		(DO-KEYSTROKE ESC)
		(DELETE-GOAL insert space) ))

As we discussed, this is already proceduralized, that is the rule is an expert rule. Write new 'novice' rules where the three keystrokes are not proceduralized. That is, you should have separate rules for each keystroke and suitable goals (such as GET-INTO-INSERT-MODE) to fire them.

answer

   (INSERT-SPACE-BEGIN-SET-MODE
IF (AND (TEST-GOAL insert space)
(TEST-CURSOR %LINE %COL)
(TEST-NOTE in command mode ))
THEN ( (ADD-GOAL get into insert mode)))
(INSERT-SPACE-END-SET-MODE
IF (AND (TEST-GOAL insert space)
(TEST-GOAL get into insert mode))
THEN ( (DO-KEYSTROKE `I')
(ADD-NOTE in insert mode)
(DELETE-GOAL get into insert mode)))
(INSERT-SPACE-DOIT
IF (AND (TEST-GOAL insert space)
(TEST-NOTE in insert mode)
(TEST-CURSOR %LINE %COL))
THEN ( (DO-KEYSTROKE SPACE)
(ADD-GOAL get into command mode)))
(INSERT-SPACE-CLEAN-UP
IF (AND (TEST-GOAL insert space)
(TEST-NOTE in insert mode)
(TEST-GOAL get into command mode))
THEN ( (DO-KEYSTROKE ESC)
(DELETE-GOAL get into command mode)
(DELETE-GOAL insert space)
(DELETE-NOTE in insert mode)
(ADD-NOTE in command mode)))

Other exercises in this chapter

ex.12.1 (ans), ex.12.2 (ans)

all exercises for this chapter