酉雞將鳴

金雞報喜。

%e9%9b%9e

韓詩外傳‧卷二

伊尹去夏入殷,田饒去魯適燕,介之推去晉入山。田饒事魯哀公而不見察,田饒謂哀公曰:「臣將去君,黃鵠舉矣。」哀公曰:「何謂也?」曰:「君獨不見夫雞乎!首戴冠者,文也,足搏距者,武也,敵在前敢鬥者、勇也,得食相告,仁也,守夜不失時,信也。雞有此五德,君猶日瀹而食之者,何也?則以其所從來者近也。夫黃鵠一舉千里,止君園池,食君魚鱉,啄君黍粱,無此五者,君猶貴之,以其所從來者遠矣。臣將去君,黃鵠舉矣!」哀公曰:「止 。吾將書子言也。」田饒曰:「臣聞:食其食者,不毀其器;陰其樹者,不折其枝。有臣不用,何書其言?」遂去,之燕。燕立以為相,三年,燕政大平,國無盜賊。哀公喟然太息,為之辟寢三月,減損上服。曰:「不慎其前,而悔其後,何可復得。」《詩》云:「逝將去汝,適彼樂國;樂國樂國,爰得我直。」

 

人人得機會,日日見生機⊙

宗鑑法林‧卷四十八

大鑒下七世
韶州雲門文偃禪師(雪峰存嗣)

示眾。人人自有光明在。看時不見暗昏昏。作麼生是自己光明。自代曰。廚庫三門。又曰。好事不如無。

愚菴盂云。雲門代兩語。一語水裏拈星。一語山頭張網。大唐國裏打鼓。新羅國裏鳴鐘。料掉沒交涉。請歸堂喫茶。靈巖儲卓拄杖云 。廚庫山門。一擊洞開了也。杓大盌小。一任諸人撿點。畢竟光明在什麼處。不見道。開口即錯。擬心即乖。

雲門上堂。乾坤之內。宇宙之間。中有一寶。秘在形山。拈鐙籠向佛殿裏。將山門來鐙籠上。作麼生。自代曰。逐物意移。又曰。雲起雷興。

靈隱禮云。雲門恁麼告報。雖則出就。藏鋒者裏又且不然。四威儀內。萬象之中。中有一寶。秘在當陽。以拄杖卓一下云。會麼。海神知貴不知價。留與人間光照夜。菴靜云。雲門恁麼說話。顯異惑眾。我者裏則不然。乾坤之內。宇宙之間。中有一寶 。秘在形山。燈籠祇是燈籠。佛殿祇是佛殿。良久云。平生肝膽向人傾。相識猶如不相識。雲菴悅云。雲門田地穩密神通妙用則不無。若較解黏去縛。猶欠一著在。

雲門示眾。十五日已前不問汝。十五日已後道將一句來。自代曰。日日是好日。

………

 

 

 

 

 

 

 

 

 

L4K ︰ 通往 Python 的道路 ── RUR-PLE 斟酌

古人說︰熟讀唐詩三百首,不會作詩也會吟。就像能寫小說的少,會讀小說的多。鏡花緣演繹『熟能生巧』,自有其理也。

鏡花緣/第031回

話說林之洋向通使道:“老兄果真舍得令愛教俺妹夫帶去,俺們就替你帶去,把病治好,順便帶來還你。”蘭音向通使垂淚道:“父親說那裏話來!母親既已去世,父親跟前別無兒女,女兒何能拋撇遠去 ?今雖抱病,不能侍奉,但父女能得團聚,心是安的,豈可一旦分為兩處!”通使道:“話雖如此,吾兒之病,若不投 奔他邦,以身就藥,何能脫體?現在病勢已到九分,若再耽捆,一經不起,教為父的何以為情?少不得也是一死!此時父女遠別,雖是下策,吾女倘能病好,便中寄我一信,為父自然心安。以此看來:遠別一層,不但不是下策,竟可保全我們兩命。況天朝為萬邦之首,各國至彼朝覲的甚多,安知日後不可搭了鄰邦船只來看我 哩。你今遠去,雖不能在家侍奉,從此我能多活幾年,也就是你仰體盡孝之處。現在承繼有人,宗祧一事,亦已無虞。你在船上,又有大賢令甥女作伴,我更放心。 為父主意已定,吾兒依我,方為孝女。不必猶疑,就拜大賢為父。此去天朝,倘能病痊,將來自有好處。”即攜蘭音向唐敖叩拜,認為義父,並拜多、林及呂氏諸 人。通使也與唐敖行劄,再再諄托。唐敖還禮道:“尊駕以兒女大事見委,小弟敢不盡心!誠忍效勞不周,有負所托,甚為惶恐!此去惟有將令愛之恙上緊療治。第 我等日後回鄉,能否繞路再到貴處,不能預定。至令愛姻事,亦惟盡心酌辦,以報知己,幸無掛懷!”只見通使僕人取了銀子送來。通使道:“這是白銀一千,內有五百,乃小弟微敬,其餘五百,為小女藥餌及婚嫁之費。至於衣服首飾,小弟均已備辦,不須大賢費心 。”眾僕人抬了八只皮箱上來。唐敖道:“令愛衣飾各物既已 預備,自應令其帶去;所賜之銀,斷不敢領。至姻嫁之費,亦何須如此之多,仍請尊駕帶回,小弟才能應命。”通使道:“小子跟前別無兒女 ,留此無用。況家有薄 田,足可度日。望大賢帶去,小子才能心安 。”多九公道:“通使大人多贈銀兩,無非愛女之意,唐兄莫若權且收下,將來俟小姐婚嫁,盡其所有,多辦妝奩送去, 豈不更妙?”唐敖連連點頭,即命來人將銀裝入箱內,抬進後艙。父女灑淚而別。蘭音從此呼呂氏為舅母,呼婉如為表姐;帶著乳母,就與婉如一同居住。

眾人收拾開船。多九公要到後面看舵,唐敖道:“九公那位高徒向來看舵甚好,何必自去?難道不看字母麼?”多九公笑道:“我倒忘了 。”唐敖取出字母,只見上面寫著:

昌○○○○○○○○○○○○○○○○○○○○○
茫○○○○○○○○○○○○○○○○○○○○○
秧○○○○○○○○○○○○○○○○○○○○○
秧梯○○○○○○○○○○○○○○○○○○○○○
羌○○○○○○○○○○○○○○○○○○○○○
商○○○○○○○○○○○○○○○○○○○○○
槍○○○○○○○○○○○○○○○○○○○○○
良○○○○○○○○○○○○○○○○○○○○○
囊○○○○○○○○○○○○○○○○○○○○○
杭○○○○○○○○○○○○○○○○○○○○○
秧批○○○○○○○○○○○○○○○○○○○○○
方○○○○○○○○○○○○○○○○○○○○○
秧低○○○○○○○○○○○○○○○○○○○○○
薑○○○○○○○○○○○○○○○○○○○○○
秧妙○○○○○○○○○○○○○○○○○○○○○
桑○○○○○○○○○○○○○○○○○○○○○
郎○○○○○○○○○○○○○○○○○○○○○
康○○○○○○○○○○○○○○○○○○○○○
倉○○○○○○○○○○○○○○○○○○○○○
昂○○○○○○○○○○○○○○○○○○○○○
娘○○○○○○○○○○○○○○○○○○○○○
滂○○○○○○○○○○○○○○○○○○○○○
香○○○○○○○○○○○○○○○○○○○○○
當○○○○○○○○○○○○○○○○○○○○○
將○○○○○○○○○○○○○○○○○○○○○
湯○○○○○○○○○○○○○○○○○○○○○
瓤○○○○○○○○○○○○○○○○○○○○○
秧兵○○○○○○○○○○○○○○○○○○○○○
幫○○○○○○○○○○○○○○○○○○○○○
岡○○○○○○○○○○○○○○○○○○○○○
臧○○○○○○○○○○○○○○○○○○○○○
張張張珠珠張珠珠珠珠珠張真中珠招齋知遮詁氈專
鷗婀鴉逶均鶯帆窩窪歪汪廂○○○○○○○○○○○○○○○○○○○○○

三人翻來複去,看了多時,絲毫不懂。林之洋道:“他這許多圈兒,含著什麼機關?大約他怕俺們學會,故意弄這迷團騙俺們的!”唐敖道:“他為一國之主,豈有騙人之理?據小弟看來:他這張、真、中 、珠……十一字,內中必藏奧妙。他若有心騙人,何不寫許多難字 ,為何單寫這十一字?其中必有道理!”多九公 道:“我們何不問問枝小姐?他生長本國,必是知音的。”林之洋把婉如、蘭音喚出,細細詢問。誰知蘭音因自幼多病,雖讀過見年書,並未學過音韻。三人聽了, 不覺興致索然,只得暫且擱起。

……

次日,三人又聚一處,講來講去,仍是不懂。多九公道:“枝小姐既不曉得音韻,我想婉如侄女他最心靈,或者教他幾遍,她能領略,也未可知。”林之洋將 婉如喚出,蘭音也隨出來,唐敖把這緣故說了 ,婉如也把“張真中珠”讀了兩遍,拿著那張字母同蘭音看了多時。蘭音猛然說道:“寄父請看上面第六行‘商’字, 若照‘張真中珠’一例讀去,豈非‘商申樁書’麼?”唐、多二人聽了,茫然不解。林之洋點頭道:“這句‘商申樁書’,俺細聽去,狠有意味。甥女為甚道恁四 字?莫非曾見韻書麼?”蘭音道:“甥女何嘗見過韻書。想是連日聽舅舅時常讀他,把耳聽滑了,不因不由說出這四字。其實甥女也不知此句從何而來。”多九公 道:“請教小姐:若照‘張夏中珠’,那個‘香’字怎樣讀?”蘭音正要回答。林之洋道:“據俺看來:是‘香欣胸虛’。”蘭音道:“舅舅說的是。”唐敖道:“ 九公不必談了。俗語說的:‘熟能生巧。’舅兄昨日讀了一夜,不但他已嚼出此中意味,並且連寄女也都聽會,所以隨問隨答,毫不費事。我們別無良法,惟有再去 狠讀,自然也就會了。”多九公連連點頭。二人複又讀了多時,唐敖不覺點頭道:“此時我也有點意思了。”林之洋道:“妹夫果真領會?俺考你一考:若照‘張真 中珠’,‘岡’字怎讀?”唐敖道:“自然是‘岡根公孤’了 。”林之洋道:“‘秧’字呢?”婉如接著道:“‘秧因雍淤’。”多九公聽了,只管望著發愣。想了 多時,忽然冷笑道:“老夫曉得了:你們在歧舌國不知怎樣騙了一部韻書,夜間暗暗讀熟,此時卻來作弄老夫。這如何使得了快些取出給我看看!”林之洋道:“俺 們何曾見過什麼韻書。如欺九公,教俺日後遇見黑女,也象你們那樣受罪。”多九公道 :“既無韻書,為何你們說的,老夫都不懂呢?”唐敖道:“其實並無韻書, 焉敢欺瞞。此時縱讓分辯,九公也不肯信;若教小弟講他所以然之故,卻又講不出。九公惟有將這‘張真中珠’再讀半日,把舌尖練熟,得了此中意味,那時才知我 們並非作弄哩。”多九公沒法,只得高聲朗誦,又讀起來。讀了多時,忽聽婉如問道:“請問姑夫:若照‘張真中珠’,不知‘方’字怎樣讀?”唐敖道:“若論‘ 方’字……”話未說完,多九公接著道:“自然是‘方分風夫’了。”唐敖拍手笑道:“如今九公可明白了。這‘方分風夫’四字,難道九公也從什麼韻書看出 麼?”多九公不覺點頭道:“原來讀熟卻有這些好處。”大家彼此又問幾句 ,都是對答如流。林之洋道:“俺們只讀得張、真、中、珠……十一字,怎麼忽然生出許 多文法?這是什麼緣故?”唐敖道:“據小弟看來:即如五聲‘通、同、桶、痛、禿’之類,只要略明大義,其餘即可類推。今日大家糊裏糊塗把字母學會,已算奇了;寄女同侄女並不習學,竟能聽會,可謂奇而又奇。而且習學之人還未學會,旁聽之人倒先聽會,若不虧寄女道破迷團,只怕我們還要亂猜哩。但張、真、中、 珠……十一字之下還有許多小字,不知是何機關?”

 

難到語言和文字不是首重日用乎?因是程式語言之『用』與『寫』亦有所別矣!故而在許多系列文本中︰

W!o+ 的《小伶鼬工坊演義》︰ 開箱大吉

W!o+ 的《小伶鼬工坊演義》︰神經網絡與深度學習【引言】

光的世界︰矩陣光學一

‧ ……

 

作者常用 Python Interactive Shell 舉例解說。希望讀者在學習過程裡,能夠嫻熟善用程式庫。浸潤久了自然熟能生巧,離寫程式或只有一步之遙的吧☆

 

 

 

 

 

 

 

 

 

L4K ︰ 通往 Python 的道路 ── RUR-PLE 觀點

如果從『GvR』之『結論』︰

Where to Go from Here…

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』的『觀點』︰

Learning Python: Child’s Play with 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 的派生‧十日談之《九》

 

 

 

 

 

 

 

 

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 之學習筆記本《巳》文章︰【䷊】包荒馮河

 

 

 

 

 

 

 

 

 

 

L4K ︰ 通往 Python 的道路 ── GvR 的一堂課

一十八步說分明,步步講解致其功︰

The Roger Frank Lessons
Introduction to Computer Science: GvR Unit

Programming with GvR

Programming a computer in a language like Python requires a precise sequencing of steps written in a language where details of syntax can be overwhelming for a beginner. Everything must be exactly right, and errors in just getting the program to run are frustrating. Often the output of beginning computer programs are text-based and uninteresting, at least to humans.

To get acquainted with the concepts of computing without getting bogged down in the syntax of a higher-level language such as Python, we begin by programming Guido van Robot. GvR is a teaching tool that presents the concepts in a visual way using a robot-language that is simple, yet powerful and extensible.

We program Guido, a simple robot that lives in a simple world. Because Guido and his world are a visual simulation, we can watch the effects of our programming statements. This activity is presented in a series of steps — tutorials with accompanying mini-labs.

Step 1 Guido’s First Steps creating .wld and .gvr files
Step 2 What’s That Sound? beepers
Step 3 Turn, Turn, Turn sequential instructions
Step 4 Just Another Brick in the Wall world file: walls
Step 5 Do The Right Thing user-generated instruction
Step 6 Robotics Times Project
Step 7 Birthday Message Project
Step 8 Decisions if statement
Step 9 You Missed Some do statement
Step 10 Let’s Dance nested user instructions
Step 11 Apple Pie or Cookies? if..elif..else statement
Step 12 Take Out the Trash Conditional Looping
Step 13 World Traveler Project
Step 14 It’s Going to Rain Project
Step 15 A Job to Do Project
Step 16 Lunchbox Project
Step 17 Community Service Revisted Project
Step 18 Where to Go from Here… Conclusion

Acknowledgements

This series of Guido van Robot exercises was written by Roger Frank. Comments and suggestions about these lessons should be sent to Jeffrey Elkner, who converted them from Roger’s Karel the Robot originals and who currently maintains them.

The Guido van Robot programming language is descended from two parent languages: Karel the Robot and Python. Karel the Robot was introduced by Richard Pattis in his book Karel the Robot: A Gentle Introduction to the Art of Programming with Pascal, John Wiley & Sons, Inc., 1981. Python is the creation of Guido van Rossum and members of the Python community. Information on Python can be found at: http://www.python.org

GvR was developed by high school computer science students at Yorktown High School in Arlington, VA, under guidance of mentor Steve Howell.

 

假使母語啟童蒙,編寫派生一路通︰

生 ︰以蠡難以測海,欲明程式語言之 秘 秘,須知那 元 元語言之『理』,需究這 組 組織之『則』,如是雖 秘 秘,終非 密 密不透風,有所遇之哉!!

Toy Parser Generator

abstract

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.

Please let me know if you use TPG in one of your projects. I will add you in the list of projects using TPG.

△ TPG 派生三之安裝︰

wget http://cdsoft.fr/tpg/TPG-3.2.2.tar.gz
tar -zxvf TPG-3.2.2.tar.gz
cd TPG-3.2.2/
sudo python3 setup.py install

 

碼 ︰家 習 。請閱讀 tpg.pdf 文件,試將下面程式中文化,比方『 + 』改作『加』,『 * 』變為『乘』,…『 sqrt 』譯釋成『根號』。會心『俚語』,根號 179 之所指。

#!/usr/bin/env python

import math
import operator
import string
import tpg

if tpg.__python__ == 3:
    operator.div = operator.truediv
    raw_input = input

def make_op(op):
    return {
        '+'   : operator.add,
        '-'   : operator.sub,
        '*'   : operator.mul,
        '/'   : operator.div,
        '%'   : operator.mod,
        '^'   : lambda x,y:x**y,
        '**'  : lambda x,y:x**y,
        'cos' : math.cos,
        'sin' : math.sin,
        'tan' : math.tan,
        'acos': math.acos,
        'asin': math.asin,
        'atan': math.atan,
        'sqr' : lambda x:x*x,
        'sqrt': math.sqrt,
        'abs' : abs,
        'norm': lambda x,y:math.sqrt(x*x+y*y),
    }[op]

class Calc(tpg.Parser, dict):
    r"""
        separator space '\s+' ;

        token pow_op    '\^|\*\*'                                              token add_op    '[+-]'
        token mul_op    '[*/%]'                                                token funct1    '(cos|sin|tan|acos|asin|atan|sqr|sqrt|abs)\b'
        token funct2    '(norm)\b'                                             token real      '(\d+\.\d*|\d*\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+'
        token integer   '\d+'                                                  token VarId     '[a-zA-Z_]\w*'

        START/e ->
                'vars'                  e=self.mem()             |   VarId/v '=' Expr/e self[v]=e
            |   Expr/e
        ;

        Var/self.get(v,0) -> VarId/v ;

        Expr/e -> Term/e ( add_op/op Term/t     e=op(e,t)                          )*         ;          Term/t -> Fact/t ( mul_op/op Fact/f t=op(t,f)
                         )*
        ;

        Fact/f ->
                add_op/op Fact/f                f=op(0,f)             |   Pow/f         ;          Pow/f -> Atom/f ( pow_op/op Fact/e f=op(f,e)
                        )?
        ;

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

        Function/y ->
                funct1/f '' Expr/x ''               y = f(x)             |   funct2/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)
        ;

    """

    def mem(self):
        vars = sorted(self.items())
        memory = [ "%s = %s"%(var, val) for (var, val) in vars ]
        return "\n\t" + "\n\t".join(memory)

print("Calc (TPG example)")
calc = Calc()
while 1:
    l = raw_input("\n:")
    if l:
        try:
            print(calc(l))
        except Exception:
            print(tpg.exc())
    else:
        break

 

行 ︰  文件總長四十七,真真是『杞』小『瓜』大,什麼也沒說,就要人家『以杞包瓜』。還會心『根號一七九』的哩!不知要不要四捨五入,小數點下有幾位,分明是罵人!!☿☹☹

 

訊 ︰☿ 后 后,上古之女王也。何時起加了個 女 女,就成了姤,祇知求『遇偶』,真不曉『後起者』造字是何肚腸??

── 摘自《M♪o 之學習筆記本《辰》組元︰【䷫】以杞包瓜