Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Karel (programming language)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Programming language}} {{Infobox programming language |name = Karel the Robot |logo = |screenshot = NikiExample.jpg |screenshot size = 250px |paradigm = [[procedural programming|procedural]] |year = 1981 |designer = [[Richard E. Pattis]] |developer = |latest release version = |latest release date = |typing = |implementations = |dialects = [[Karel (programming language)#Variants and descendants|Some localized language variants]] |influenced_by = [[Pascal (programming language)|Pascal]] |influenced = Karel++, [[AgentSheets]], [[Guido van Robot]] }} '''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]], [[California]]. The language is named after [[Karel Čapek]], a [[Czech people|Czech]] writer who introduced the word ''[[robot]]'' in his play [[R.U.R.]]<ref>{{Cite web |url=http://capek.misto.cz/english/robot.html |title=Who did actually invent the word 'robot' and what does it mean? |access-date=25 July 2013 |archive-url=https://web.archive.org/web/20130727132806/http://capek.misto.cz/english/robot.html |archive-date=27 July 2013}}</ref><ref>[[Ivan Margolius|Margolius, Ivan]] (Autumn 2017) [https://czechfriends.net/images/RobotsMargoliusJul2017.pdf "The Robot of Prague"] {{webarchive|url=https://web.archive.org/web/20170911115134/https://czechfriends.net/images/RobotsMargoliusJul2017.pdf |date=11 September 2017 }} ''The Friends of Czech Heritage Newsletter'' no. 17, pp.3-6</ref> ==Principles== A [[computer program|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: <code>move</code> (Karel moves by one square in the direction he is facing), <code>turnLeft</code> (Karel turns 90 ° left), <code>putBeeper</code> (Karel puts a beeper on the square he is standing at), <code>pickBeeper</code> (Karel lifts a beeper off the square he is standing at), and <code>turnoff</code> (Karel switches himself off, the program ends). Karel can also perform [[boolean data type|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 [[instruction (computer science)|instruction]]s by defining them in terms of the five basic instructions, and by using conditional [[control flow]] statements <code>if</code> and <code>while</code> with environment queries, and by using the <code>iterate</code> construct.{{Citation needed|date=April 2020}} ===Example=== The following is a simple example of Karel syntax: BEGINNING-OF-PROGRAM DEFINE turnRight AS BEGIN turnLeft; turnLeft; turnLeft; END BEGINNING-OF-EXECUTION ITERATE 3 TIMES BEGIN turnRight; move END turnoff END-OF-EXECUTION END-OF-PROGRAM == Specification == The following implementation is Karel in the [[Python (programming language)|Python programming language]].<ref>{{Cite web |last=Piech |first=Chris |last2=Roberts |first2=Eric |date=January 2019 |title=Karel the Robot Learns Python. Appendix: Reference |url=https://compedu.stanford.edu/karel-reader/docs/python/en/reference.html |access-date=2023-06-12 |website=compedu.stanford.edu}}</ref> Other implementations are available. === Primitive functions === The following are the primitive functions. <code>move()</code>: Karel moves one square in the direction it is facing. <code>turn_left()</code>: Karel turns left by 90 degrees. <code>put_beeper()</code>: Karel puts a beeper on its current square. <code>pick_beeper()</code>: Karel picks up a beeper from its current square. <code>paint_corner(COLOR_NAME)</code>: Karel paints its current corner with a color. There is a finite list of available colors. === Program Structures === Karel programs are structured in the following way: * Comments: Any line starting with <code>#</code> is a comment and is ignored by the interpreter. * Functions in Karel are declared using <code>def</code>, followed by the function name and parentheses. The body of the function follows in subsequent lines. * <code>main()</code>: A program run executes the <code>main</code> function. The other functions are not executed unless called. === Conditions in Karel === Karel can respond to certain conditions in its world: <code>front_is_clear(),</code><code>beepers_present(),</code> <code>beepers_in_bag(),</code> <code>left_is_clear(),</code> <code>right_is_clear(),</code> <code>facing_north(),</code> <code>facing_south()</code><code>,</code> <code>facing_east()</code><code>,</code> <code>facing_west()</code> And their inverses: <code>front_is_blocked(),</code> <code>no_beepers_present(),</code> <code>no_beepers_in_bag()</code><code>,</code> <code>left_is_blocked()</code><code>,</code> <code>right_is_blocked(),</code> <code>not_facing_north(),</code> <code>not_facing_south(),</code> <code>not_facing_east(),</code> <code>not_facing_west()</code><code>.</code> It can also check the current block's color by <code>corner_color_is(COLOR_NAME)</code>. === Conditions and Loops === There are two control structures: * Conditional execution using <code>if</code> and <code>else</code>. * Loops using <code>for</code> and <code>while</code>. ==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 language|Czech]] (the programming language was quite popular in [[Czechoslovakia]]). 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 (programming language)|Java]]. A REALbasic implementation, rbKarel,<ref>{{Cite web|url=https://code.google.com/p/rbstuff/wiki/rbKarelOverview|title=Google Code Archive - Long-term storage for Google Code Project Hosting}}</ref> 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<ref>{{cite web |url=http://www.emil.input.sk/info_en.htm |title=Introduction (EN) |website=www.emil.input.sk |url-status=dead |archive-url=https://web.archive.org/web/20101102224734/http://www.emil.input.sk/info_en.htm |archive-date=2010-11-02}}</ref>'' uses a [[3D computer graphics|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 language|English]], [[Czech language|Czech]] and [[Slovak language|Slovak]]. A proprietary language which is also called Karel is used to program the robots of [[FANUC Robotics]]. However, FANUC Karel is derived from [[Pascal programming language|Pascal]]. The language has also been implemented as Karel the Dog in [[JavaScript]] by [[CodeHS]]. Similar to the original language, this implementation features Karel in a grid world. Programmers use and build upon Karel's simple vocabulary of commands to accomplish programming tasks. Instead of putting and picking beepers, Karel the Dog puts and takes tennis balls. A German version of Karel is named "Robot Karol".<ref>{{cite web |title=Robot Karol – Escape the Maze {{!}} Schülerlabor Informatik - InfoSphere, Informatik entdecken in Modulen für alle Schulformen & Klassenstufen |url=https://schuelerlabor.informatik.rwth-aachen.de/module/robot-karol |website=schuelerlabor.informatik.rwth-aachen.de |access-date=29 December 2020}}</ref> == See also == * [[List of educational programming languages|Educational programming language]] * [[RoboMind]] - An educational alternative programming environment * [[RUR-PLE]] - another "learn Python" tool based on ideas in Karel * [[CodeHS]] - introductory computer science education using Karel in JavaScript == Further reading == * 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}}. == References == {{reflist}} ==External links== * [https://web.archive.org/web/20230405201344/https://mormegil.wz.cz/prog/karel/prog_doc.htm Karel syntax] * [http://xkarel.sourceforge.net xKarel] by R. Dostal and P. Abrahamczik (created 1997) * [http://karel.sourceforge.net Karel] by T. Mitchell (created 2000) * [http://primepuzzle.com/karel/ Karel in tiny-c] {{Webarchive|url=https://web.archive.org/web/20191128164514/http://primepuzzle.com/karel/ |date=2019-11-28 }} by Lee Bradley (created 2013) * [http://karel.cloudmakers.eu Karel for iPad] by CloudMakers (created 2014) * [http://www.codehs.com Karel in JavaScript] by CodeHS * [https://metacpan.org/pod/Karel Karel in Perl 5] by E. Choroba (created 2016) * [https://sourceforge.net/projects/karel-3d/ Karel-3D in JavaScript and C++ (sk) (en) (de) (es)] (created 2017, 2018) * [http://gvr.sourceforge.net/ Guido van Robot (GvR) - Karel in Python] (created 2006, 2010) {{Authority control}} [[Category:Educational programming languages]] [[Category:Procedural programming languages]] [[Category:Programming languages created in 1981]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Authority control
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite web
(
edit
)
Template:ISBN
(
edit
)
Template:Infobox programming language
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Webarchive
(
edit
)