L4K ︰ 通往 Python 的道路 ── RUR-PLE 課綱

由 RUR-PLE 的宣言觀之︰

Learning Python: Child’s Play with RUR-PLE!

Apprendre le langage Python avec RUR-PLE: un jeu d’enfants!

André Roberge, © 2004, 2005

Learning to program computer should be fun, for adults and children alike. RUR-PLE is an environment designed to help you learn computer programming using the language Python. To use RUR-PLE, you need wxPython. You can learn more about RUR-PLE or you can go to the download page.

 

,它直指派生 Python 語言。自課綱內容來看︰

List of lessons

  1. About the browser
    This first lesson explains the use of the browser included within RUR-PLE.
  2. Reeborg explores its world
    In this lesson, you will start getting familiar with Reeborg’s environment and learn to use arrows on the keyboard to make Reeborg move.
  3. First program
    This lesson what we mean by computer program and introduces two instructions for Reeborg: move() and turn_off().
  4. Dealing with eRRoRs
    Learning about the case sensitivity of Python.
  5. Any comments? Avez-vous des commentaires?
    We learn how to add additional explanations meant only for humans in programs. These are called comments. We also learn about translating the instructions obeyed by Reeborg into other human languages. This is closely related to the concept of variables which will be introduced much later.
  6. Making a left turn
    We learn about another instruction for Reeborg: turn_left().
  7. Beepers
    We learn about beepers and the last two commands that Reeborg can obey: pick_beeper() and put_beeper().
  8. Darn bugs!
    In this lesson we learn about bugs and how RUR-PLE can help us find and quash them.
  9. Building walls
    We learn how to add or remove walls in Reeborg’s world; this lesson concludes with a few programming challenges.
  10. Definitely avoiding repetitions
    In this lesson, we learn our first python keyword: def.
  11. Avoiding repetitions, again!
    Here, we learn how Reeborg can repeat instructions automatically.
  12. If only Reeborg could decide on his own …
    In this lesson, we learn our second Python keyword: if.
  13. Listen to me … or else ….
    In this lesson, we learn our third Python keyword: else.
  14. If, else, if, else, ….
    In this lesson, we learn our fourth and fifth Python keywords: elif and pass.
  15. Not true!?
    In this lesson, we learn our sixth Python keyword: not.
  16. For a while
    In this lesson, we learn our seventh Python keyword: while.
  17. Amazing – part 1
    We put together all we’ve learned so far to solve a series of exercises, with a surprising conclusion.
  18. Amazing – part 2
  19. Amazing – part 3
  20. Amazing – part 4
  21. Amazing – part 5
  22. It’s raining!
    Help Reeborg close the window in his house to prevent the rain from coming in.
  23. After the storm
    Help Reeborg clean up his yard after a wind storm.
  24. Sorting
    Help Reeborg sort some piles of beepers into ascending order.
  25. Avoiding repetitions – the important stuff
    In this lesson we learn about the Python keywords from and import, as well as the pseudo-keyword as.
  26. Teaching Reeborg to add.
    We teach Reeborg how to add two numbers on his own. After this lesson, we will temporarily leave Reeborg’s world to learn more about Python itself.
  27. Python already knows how to add.
    In this lesson, we explore how Python adds, subtracts, multiplies, divides, …, numbers.

 

大體類同於 GvR 的教程。於是有問焉?果真可辨別哪個較『有趣』嗎??此作者之所以寫 M♪o 『入出針文法』之因緣也︰

碼 ︰無 習 。無課。

行 習 行習︰茲將實習 機 機板『入出針文法』初步整理如下

,待會習時再討論改善以及擴張︰

‧ 入出針   BCM制針碼表達式  [入針 | 出針]
‧讀入   BCM制針碼表達式
‧寫出   BCM制針碼表達式   [開 | 關]
‧打開蜂鳴器
‧蜂鳴器   [響聲 | 禁音]   頻率表達式Hz
‧顯示   表達式

△ 算術運算︰加、減、乘、除、剩【※餘數】、『^』與『**』指數運算。

△ 一元函數︰餘弦、正弦、切弦、acos 、asin 、atan 、平方、根號 、正值。

△ 二元函數︰ norm 。

△ 變元記憶。

訊 ︰☿ 《風俗通》裡記載:杜宣夏至日赴飲,見酒杯中似有蛇,然不敢不飲。酒後胸腹痛切,多方醫治不愈。後得知壁上赤弩照于杯中,影如蛇,病即愈。

, 未雨先綢繆!又豈是杯弓蛇影胡疑猜?寧夜靜思,

夏至日作》權德輿

睿樞無停運,
四序相錯行。
寄言赫曦景,
今日一陰生。

忽兒,一日又將盡!!

─── 摘自《M♪o 之學習筆記本《巳》文章︰【䷁】黃裳元吉

 

猶恐揠苗助長之嫌,因補平說矣︰

今兒學堂氣氛有些低迷,同學們意興闌珊,有點悶悶不樂。想來是因為昨天有些議題,不能定奪結論,某些改寫嘗試,失敗告終。這因『辨』而『辯』與由『辯』能『辨』,應該如何決定分際?

《 文 》文說︰

辨,判也。从刀辡聲。

辯,治也。从言在辡之閒。

,彷彿說了似沒說!

沒多時學長來了。

派︰ 同學們,大家好。昨兒因故請假,晚上讀了 M♪o 的課堂摘記,看到大家合力完成的 TuxIOme 程式深感驚豔。別說當年我們學習時沒有這樣的創舉,就算當初在小學堂課綱之訂定時,也未曾設想過,真可以小學堂裡講程式文法的哩!所以今兒自備禮物 ── 環境溫度感測器 ──,給你們嘉獎,替同學們加油。同時特傳能看影音的 Kodi 安裝 秘 技 秘技,為大家助興。【熱烈鼓掌】

雖然說『包荒馮河』在於『勇』,更在『朋不遐遺』。 議 論 議論之旨,重在得 理 理。同或不同,以 辨辯 ,貴能 和 同異,方謂得 宜 宜。

程式語言的文法,道理博大精深,大家既已敲門叩關,更應當細思幕後法則,往往牽一髮而動全身。於此略對入出針文法,作個 平 平說︰

【函元之不妥】

通常研習程式文法實務,精通了算術表達式,大概思過半矣。這事早由 λ 運算所揭示,所以知道『函式求值』與『變元代換』的概念看來似乎簡單,其中的精巧細密,除非深入探究,並不容易掌握。如果考察派生語法,它並沒有『抽象函數』運算︰

(f + g) (x) = f (x) + g (x)

(f - g) (x) = f (x) - g (x)

(f * g) (x) = f (x) * g (x)

(f / g) (x) = f (x) / g (x)

(f \circ g) (x) = f (g (x) )

,這是因為首先『 def 』關鍵字所定義的『函式』,可以不是數學上講的『函數』,而是執行某種『功能』 function 。 再者從語用上說,針對特定領域應用,設計特殊語法,並不是普通程式語言應該專注的目標,多半經由『程式庫』來作擴充。比方講 NumPy 方便了科學運算, SymPy 開啟符號代數系統。它們並不直接擴張 Python 的基本語法。因此對於入出針文法,也需要思考它的『目的性』。由於 TPG 只是普通派生定義的『 class 』類,所謂文法的『內』與『外』就有很多彈性,可以在應用上作適度規劃。由此觀之,函元 ,或該叫做函式,之擴張並非『必要的』,因此認為不妥。

【文法之整合】

假使將 TuxIOme 的系統溫度文法,如此修改

# 原先
            |   "系統溫度"                        e = 讀取系統溫度()         ; # 改作             |   "系統溫度" self["CPU溫度"] = e = 讀取系統溫度()
        ;

,原先的用法依舊,『變元』裡將增加一項『 CPU溫度』,於是就可以用『顯示』文法,將系統溫度顯示在數碼管上。現今又多了『環境溫度』的感測器,可以思考如何『相容』『整合』的作文法擴充 。

【功能之衡量】

現在已經有了 IRTX 和 IRRX 的『功能』。如果我們將 紅 外 線紅外線發射碼中的 KEY_0、KEY_1 … KEY_9 看成『數字碼』,用來傳遞『四位數字訊息』,舉例︰

1314 ──→ 一生一世

5200 ──→ 我愛人人

等等,可以用『明文』,也可以用『亂數加密』成『密訊』。如此除了將需要『明文』或『密訊』的『發文』與『收文』之文法外,還需要『亂數』產生器,下面程式片段定義了一種『基本』 Atom 原子資料,稱為『Random』,是『四位亂數』的製造者,

        Atom/a ->
                real/a
            |   integer/a
            |   Function/a
            |   Var/a
            |   '' Expr/a ''
            |   Random/a
        ;

        Function/y ->
                函數一/f '' Expr/x ''               y = f(x)             |   函數二/f '<img src="http://www.freesandal.org/wp-content/ql-cache/quicklatex.com-5618a7a7b23dfd84e41ef622fed8142e_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="' Expr/x1 ',' Expr/x2 '" title="Rendered by QuickLaTeX.com" height="19" width="165" style="vertical-align: -5px;"/>' y = f(x1,x2)
        ;

        Random/x -> "四位亂數"                          $ x = random.randint(0, 9999)
        ;

,把它當成起始點,試以『應用』為中心,探索『亂數』的用途。

─── 摘自《M♪o 之學習筆記本《巳》文章︰【䷊】包荒馮河