Karel (programming language)

From Wikipedia, the free encyclopedia
  (Redirected from Karel programming language)
Jump to: navigation, search
Niki the robot
Karel the Robot in NCLab
Karel the Robot
Paradigm(s) procedural
Appeared in 1981
Designed by Richard E. Pattis
Dialects Some localized language variants
Influenced by Pascal
Influenced Karel++

Karel is an educational programming language for beginners, created by Richard E. Pattis in his book Karel The Robot: A Gentle Introduction to the Art of Programming. Pattis used the language in his courses at Stanford University. The language is named after Karel Čapek, a Czech writer who introduced the word robot.

Contents

[edit] Principles

A program in Karel is used to control a simple robot named Karel that lives in an environment consisting of a grid of streets (left-right) and avenues (up-down). Karel understands five basic instructions: move (Karel moves by one square in the direction he is facing), turnleft (Karel turns 90 ° left), putbeeper (Karel puts a beeper on the square he is standing at), pickbeeper (Karel lifts a beeper off the square he is standing at), and turnoff (Karel switches himself off, the program ends). Karel can also perform boolean queries about his immediate environment, asking whether there is a beeper where he is standing, whether there are barriers next to him, and about the direction he is facing. A programmer can create additional instructions by defining them in terms of the five basic instructions, and by using conditional control flow statements if and while with environment queries, and by using the iterate construct.

[edit] Example

The following is a simple example of Karel syntax (a ";" indicates end of instruction, can be omitted if current instruction is followed by an END).

BEGINNING-OF-PROGRAM
 
 DEFINE turnright AS
 BEGIN
   turnleft;
   turnleft;
   turnleft
 END
 
 BEGINNING-OF-EXECUTION
   ITERATE 3 TIMES
     turnright;
     move;
     turnoff
 END-OF-EXECUTION
 
END-OF-PROGRAM

[edit] Variants and descendants

The language has inspired the development of various clones and similar educational languages. As the language is intended for beginners, localized variants exist in some languages, notably Czech (the programming language was quite popular in Czechoslovakia). The Slovak version, called Robot Karol++, contains further enhancements and it has been itself translated to English, German and Czech.

[edit] Online version in NCLab

An interactive graphical version of Karel the Robot is available free of charge for personal non-commercial purposes in NCLab. Compared to the original version which was close to Pascal, the syntax of Karel in NCLab is closer to Python. Moreover, to make the language more accessible to children, keywords have been simplified to "go", "turn", "get" and "put". The application has four modes:

  • Manual Mode: Kids of age 3+ learn to control the robot using the mouse.
  • Program Mode: Level 1 is a bridge between the manual and program control - the user is only allowed to use commands that match the names of the buttons in Manual Mode. Level 2 adds standard programming tools such as loops, conditions, and compound commands. Additional levels are in preparation.
  • Build Mode: The user can build and save his own mazes.
  • Game Mode: Enables the user to clone and play games created by others, as well as create his/her own games, play them, and eventually publish them and make available to others.

[edit] Other variants

The principles of Karel were updated to the object-oriented programming paradigm in a new programming language called Karel++. Karel++ is conceptually based on Karel, but uses a completely new syntax, similar to Java.

A proprietary language which is also called Karel is used to program the robots of FANUC Robotics. However, FANUC Karel is derived from Pascal.

A REALbasic implementation, rbKarel [1], provides the basic Karel commands within an RBScript environment with BASIC syntax being used for loops and conditionals. This teaching project provides a cross-platform GUI for Karel experiments including single-stepping and spoken output.

A Karel-inspired language and environment called Robot Emil uses a 3D view of the robot's world. Robot Emil offers a large palette of objects that can be placed to depict walls, windows (transparency), water and grass. The camera may be moved freely throughout the 3D environment. The robot may be controlled interactively with buttons in the GUI, or by programs written in Emil's Karel-like programming language. The author states that the program is free for use by schools, students and children. Versions are available in English, Czech and Slovak.

[edit] See also

[edit] References

  • Richard E. Pattis. Karel The Robot: A Gentle Introduction to the Art of Programming. John Wiley & Sons, 1981. ISBN 0-471-59725-2.
  • Joseph Bergin, Mark Stehlik, Jim Roberts, Richard E. Pattis. Karel++: A Gentle Introduction to the Art of Object-Oriented Programming. John Wiley & Sons, 1996. ISBN 0-471-13809-6.

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages