如果從『GvR』之『結論』︰
Conclusion
Guido is starting to realize that there are some things he cannot do. In the projects where Guido traveled, he had no memory of how big the world was. He has no way to keep track of a count. He tried to tell his parents about the journey but when they asked How far did you go?
he didn’t know. In the rain
project where Guido had to close the windows, he had no way to remember where he started, at the door. He had to leave a beeper there to know when he had gone all around the house.
What Guido would like is a way to remember things. He read in a computer programming book about a part of a program called a variable that could be used to store numbers or letters or even words. Variables can hold a number value and that value can be changed. If he had a variable, he could increase the value in his variable by one for each step and know how many steps he had taken. If he had a two variables, he could store the street and the avenue where he stood at the door in the rain
project and wouldn’t have needed to drop a beeper there.
Alas, Guido does not have variables. Sadly, he knows he never will. He has heard rumors about other programming languages, such as Python, which have all of his capabilities and much more, including variables and the ability to listen and speak (input and output instructions) and even the ability to create whole new types of robots (object oriented programming and inheritance).
Its time to say goodbye to Guido and his world. He will wait patiently for the next class of students while you move on and learn more about programming as you continue your journey in Computer Science.
到『RUR-PLE』的『觀點』︰
André Roberge, © 2005
What is RUR-PLE
Summary of instructions
Acknowledgements
About the browser
What is RUR-PLE
Simply put, RUR-PLE is a Python Learning Environment. With the assistance of a robot named Reeborg , we will explore the fun of programming in the Python language. But first, a little bit of background:
The word ‘robot’ entered our language through the 1920 play R.U.R. (Rossum’s Universal Robots) by Czech writer Karel Capek. Little did Capek know how widespread the word would become!
Karel Capek’s name cropped up in 1981, when Richard Pattis wrote a delightful little book titled Karel the Robot, a Gentle Introduction to the Art of Programming. In this book, Pattis introduces the main concepts of sequential programming (including loops and decisions, but not variable assignments) using the paradigm of instructing a robot capable of only four basic actions (turning left, moving one step forward, picking up and putting down beepers). Through the magic of programming, the robot learns to combine those four basic actions in order to accomplish tasks of increasing complexity. Pattis used Pascal, the preferred language of the day, as a means of “teaching” the robot new tricks. Since then, many new versions of Karel the Robot have appeared, used to introducing various computer languages, notably Java and C++, which are both based on the modern Object-Oriented Programming (OOP) approach.
However, since the complexity of Java and C++ contrasts with the simplicity of the robot world, these languages seem at odds with the idea of providing a Gentle Introduction to the Art of Programming.
Enter Python!… Named after the famous Monty Python’s Flying Circus by its creator, Guido van Rossum. Python, like Java and C++, is an OOP language. However Python also allows a non-OOP programming style more suitable for interacting with Pattis’s robot. A first implementation of Karel the Robot in Python was called PyKarel. The current implementation is called Guido van Robot (GvR for short), and is available at sourceforge.net.
RUR: a Python Learning Environment (rur-ple) is a “new and improved” version of GvR that extends Pattis’ ideas and allows a smooth transition to the use of variables as well as functions/methods, classes and objects. Rur-ple is a complete environment, its lessons cover the use of all of Python’s keywords. A Python interpreter and simple editor are included to explore Python outside the robot’s world.
Reeborg is a robot built on the 1981 Pattis’ model … and it is starting to show its age. It has an oil leak, which allows us to follow its trail. Its compass is broken; it only knows if it is facing North or not, unlike Karel or Guido who could determine their orientation with respect to all four cardinal points.
Pattis’ Karel the Robot was named after the author Karel Capek, who popularized the word robot in his play Rossum’s Universal Robots (RUR). While rur-ple shares the basic RUR acronym, in this case it stands for Roberge’s Used Robot. However, through the magic of Guido van Rossum’s Python, you can learn how to fix it and design a better one, worthy of the name Rossum’s Universal Robot.
來看,核心概念落在藉著規劃之『如何寫程式』的環境,透過課程了解『程式是什麼』,促進『程式語言』之學習。
以簡馭繁固然容易開始,課程緊湊有趣可以輕鬆上手。然而………果真不能在『派生體系』裡創造『微環境』直攻 Python 的乎!!
於是常若有所思夫??
要如何看待這些『建置』 implementation 的呢?也許好好『履行』 Implementation 其一,將自可及於『其它』,或若有『所思』,也可讀讀『淮南子』之《說林訓》︰
然後大膽『解讀』《 TPG 》 Toy Parser Generator 『原始碼』,『遊藝』於『文法』『語意』物件之中,『採擷』 TPG 之『自生自成』的『精華』︰
Toy Parser Generator is a lexical and syntactic parser generator for Python. This generator was born from a simple statement: YACC is too complex to use in simple cases (calculators, configuration files, small programming languages, …).
TPG can very simply write parsers that are usefull for most every day needs (even if it can’t make your coffee). With a very clear and simple syntax, you can write an attributed grammar that is translated into a recursive descendant parser. TPG generated code is very closed to the original grammar. This means that the parser works like the grammar. A grammar rule can be seen as a method of the parser class, symbols as method calls, attributes as method parameters and semantic values as return values. You can also add Python code directly into grammar rules and build abstract syntax trees while parsing.
The first application of TPG is TPG itself. The first (not released) version of TPG has been written by hand then was used to generate next versions. Now TPG can generate itself.
For an uptodate documentation, please read tpg.pdf.
─── 摘自《W!o 的派生‧十日談之《九》》