Learn How to Think with Karel the Robot. 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.
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.
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.
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:
3DEFINE turnright AS
11 ITERATE 3 TIMES
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:
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
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.
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.
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.
Note: For all review questions in this book: None, one, or multiple answers may be correct.
- the song Robotic Mind.
- the book Uprising of Robots.
- the theater play R.U.R.
- the movie E.T.
- Karel Čapek
- Pavel Solin
- Richard E. Pattis
- John von Neumann
- To help students learn logic.
- To help students learn keyboarding.
- To help students learn geometry.
- To help students learn robotics.
- One time.
- Two times.
- At least three times.
- Karelw as never implemented in the past.
- The colon : is not used in the Karel language.
- Python contains all commands which are in Karel.
- Karel contains all commands which are in Python.
- Karel can use GPS coordinates.
- Walls only.
- Beepers only.
- Collectible objects, obstacles, and containers.
- Walls and beepers.
- Collect objects which are beneath him.
- Detect obstacles which are in front of him.
- Detect if he is facing North.
- Place objects on the floor and/or in containers.
- Karel is simplified C++.
- Karel is a modern version of Cobol.
- Karel is only for those who don’t want to learn any other programming language.
- With Karel, one can learn programming methodology easily without struggling with the technical complexity of "real" programming languages.
Table of Contents
- 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