Learn How to Think with Karel the Robot. Chapter 1. Introduction
Chapter 1
Introduction
In this chapter you will learn:
- About a Czech writer Karel Čapek who predicted human-like machines and invented the word "robot".
- About a Stanford University professor R.E. Pattis who created an educational programming language to help his students learn logic.
- Basic facts about the Karel language, and how it differs from other programming languages.
1.1. Karel Čapek and his 1921 play R.U.R.
Karel Čapek (1890 - 1938) was a legendary Czech science fiction writer who first predicted human-like machines and invented the word "robot" in his 1921 science fiction play R.U.R. (Rossum’s Universal Robots). The play was soon translated to more than 20 languages. In his visionary novels, Karel Čapek also predicted nuclear weapons, the Second World War, and consumer society. He was nominated for the Nobel Prize in Literature seven times.
1.2. Brief history of the Karel language
The educational programming language Karel the Robot was introduced by Dr. Richard E. Pattis at the Stanford University in his book Karel The Robot: A Gentle Introduction to the Art of Programming in 1981.
R.E. Pattis created the language to help his students learn programming logic. Nowadays, Karel is used at countless schools in the world. In 2006, R.E. Pattis was recognized by the Association for Computing Machinery (ACM) as a Pioneering Innovator Who Significantly Advanced the Digital Age.
1.3. Various past implementations
There have been a number of different implementations of the Karel language since the 1980s. Some of them can still be downloaded from the web and used today while some others were designed for older operating systems (such as Windows 3.1) which no longer are in use:
1.4. New Karel language based on Python
The original Karel language was based on Pascal, a popular programming language of
the 1980s. For illustration, here is a sample program written using the original Karel
language:
2
3DEFINE turnright AS
4BEGIN
5 turnleft
6 turnleft
7 turnleft
8END
9
10BEGINNING-OF-EXECUTION
11 ITERATE 3 TIMES
12 BEGIN
13 turnright
14 move
15 END
16 turnoff
17END-OF-EXECUTION
18
19END-OF-PROGRAM
Since Pascal is not a mainstream programming language today, we revised the Karel language
and adjusted its syntax to be similar to Python, a major programming language of modern
engineering and science. This change made Karel much easier to use. For illustration, here is the
above program again, written in the new Karel language:
1.5. Command right and some other new features
The new Karel language has a built-in command right for the right turn and the corresponding
animation. In the original Karel language, the robot had to make three left turns to turn right. As
a result, when solving more complex tasks, the robot was spinning a lot. In fact, he resembled a
tornado passing through the maze. With this command, Program 1.2 can be reduced to just
three lines:
For convenience, long keywords were replaced with shorter ones, such as leftturn with left, move with go, pickbeeper with get, putbeeper with put. Complicated syntax features such as semicolons and parentheses were removed for easier use.
And finally, the original Karel only had beepers and walls in the maze. We added many other collectible objects such as gems, nuggets, spiders and snakes. We also added many other types of obstacles (which Karel must not run into or he explodes) such as water, fire, skulls, scorpions and acid. The new Karel world also has containers (where he can drop off collectible objects) such as marks, boxes, baskets, chests and fishing nets. More about creating mazes and making games will be explained in Appendix A.
1.6. What can Karel do?
Karel is a determined robot that can cross a jungle or a desert, explore caves, collect pearls on the ocean’s floor, climb icy mountains and do many other cool things:
He can detect collectible objects beneath him and obstacles in front of him. He can detect if he is facing North and if he is at his home square. He can also collect objects and/or remember their GPS coordinates, store them in variables and lists, and place objects on the floor or in containers as needed.
1.7. How does Karel differ from Python?
Despite its playful appearance, Karel features all key concepts of modern procedural programming. Technically speaking, it is a complete Turing machine. As you will see later, the Karel programs presented in this textbook range from very simple to extremely challenging.
As we already mentioned, the new version of the Karel language is influenced by Python. Basic Python concepts such as numbers, text strings, logical values, and lists are implemented in Karel. Also, Karel knows basic Python statements. However, not every code written in Karel will work in Python and vice versa. Karel does not use the colon symbol : after compound statements if, while, def, etc. Karel has the loop repeat which is a simplified version of the Python for loop. Also, Karel has a set of its own commands and functions such as go, left, right which are not available in Python.
1.8. Review questions
Note: For all review questions in this book: None, one, or multiple answers may be correct.
QUESTION 1.3. The word "robot" was first introduced in
- A
- the song Robotic Mind.
- B
- the book Uprising of Robots.
- C
- the theater play R.U.R.
- D
- the movie E.T.
QUESTION 1.4. Who created the educational programming language Karel the Robot?
- A
- Karel Čapek
- B
- Pavel Solin
- C
- Richard E. Pattis
- D
- John von Neumann
QUESTION 1.5. Name the university where Karel the Robot was first used!
- A
- MIT
- B
- Princeton
- C
- Harvard
- D
- Stanford
QUESTION 1.7. Why was Karel the Robot created?
- A
- To help students learn logic.
- B
- To help students learn keyboarding.
- C
- To help students learn geometry.
- D
- To help students learn robotics.
QUESTION 1.8. What major programming language influenced the original Karel language?
- A
- Cobol
- B
- Basic
- C
- Fortran
- D
- Pascal
QUESTION 1.9. How many times was Karel implemented in the past?
- A
- One time.
- B
- Two times.
- C
- At least three times.
- D
- Karelw as never implemented in the past.
QUESTION 1.11. What command was newly introduced in the new Karel language?
- A
- left
- B
- right
- C
- jump
- D
- turn
QUESTION 1.12. Which of the following statements are true?
- A
- The colon : is not used in the Karel language.
- B
- Python contains all commands which are in Karel.
- C
- Karel contains all commands which are in Python.
- D
- Karel can use GPS coordinates.
QUESTION 1.13. What types of objects can be found in Karel’s maze in NCLab?
- A
- Walls only.
- B
- Beepers only.
- C
- Collectible objects, obstacles, and containers.
- D
- Walls and beepers.
QUESTION 1.14. What can Karel do?
- A
- Collect objects which are beneath him.
- B
- Detect obstacles which are in front of him.
- C
- Detect if he is facing North.
- D
- Place objects on the floor and/or in containers.
QUESTION 1.15. What is the main benefit of learning programming with Karel the Robot?
- A
- Karel is simplified C++.
- B
- Karel is a modern version of Cobol.
- C
- Karel is only for those who don’t want to learn any other programming language.
- D
- With Karel, one can learn programming methodology easily without struggling with the technical complexity of "real" programming languages.
Table of Contents
- About
- 1. Introduction
- 2. Basic Commands
- 3. Counting Loop
- 4. Conditions
- 5. Conditional Loop
- 6. Custom Commands
- 7. Variables
- 8. Functions
- 9. Text Strings
- 10. Testing Your Programs
- 11. Boolean Values, Variables, Expressions, and Functions
- 12. Randomness and Probability
- 13. Lists
- 14. Recursion
- 15. Advanced Applications
- Appendix A. Karel App in NCLab
- Appendix B. Self-Paced Karel Course in NCLab