2012年10月17日 星期三

JForthBlocks--Forth說 I,J,K 即非 I,J,K 是名 I,J,K

Jimmy's papa為了讓Jimmy小朋友認認字,收收心,偶而會要他念幾頁金剛經,

經中須菩提有云
【 世尊說:我見、人見、眾生見、壽者見, “Because (when) the Tathagata speaks of the view of an ego, a Personality, a being and a life, 即非我見、人見、眾生見、壽者見,是名我見、人見、眾生見、壽者見 “it is not really, (but) is (expediently) called the view of an ego, a personality a being and a life.” 】。
雖然不甚了解此段經文的意義,反正是經典,小朋友有唸有保佑(BoBee)啦!!

不過今天寫Forth小範例時,使用Loop Index卻遇見非預期的結果,讓Jimmy's papa見識到了
Forth說 I,J,K 即非 I,J,K 是名 I,J,K
寫慣一般程式語言的人,或許看了書上的Forth程式碼會主觀認定I是最內迴圈索引,J是外迴圈索引,K是外外迴圈索引

不過事實上Forth的I,J,K是指返回堆疊(Return Stack)當下時間點實際暫存的迴圈體索引, 所以光看程式會以為外外迴圈的索引值要用K,但實際執行取索引值時,返回堆疊(Return Stack)或許只有外外迴圈一個迴圈體而已 ,所以只能用I取索引值
寄件者 scratchlab02
寄件者 scratchlab02
底下是XML,直接貼到XML編輯區,便能自動載入積木程式
<xml xmlns="http://www.w3.org/1999/xhtml"><block type="processing_Setup" notchtype="LEFT_RIGHT" inline="false" x="54" y="20"><value name="NEXTWORD"><block type="variable_value" notchtype="LEFT_RIGHT" inline="false"><title name="NAME">psjObj</title><value name="NEXTWORD"><block type="procedures_callnoreturn" notchtype="LEFT_RIGHT" inline="false"><mutation name="psjObj"></mutation><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">230</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">230</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">230</title><value name="NEXTWORD"><block type="processing_BackgroundByValues" notchtype="LEFT_RIGHT" inline="false"></block></value></block></value></block></value></block></value></block></value></block></value></block><block type="procedures_callnoreturn" notchtype="LEFT_RIGHT" inline="false" x="55" y="58"><mutation name="psjObj"></mutation><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">0</title><value name="NEXTWORD"><block type="processing_FillByGray" notchtype="LEFT_RIGHT" inline="false"></block></value></block></value></block><block type="compile_define_highword" notchtype="Top_Bottom_Right" inline="false" x="55" y="96"><title name="NAME">MyHighWord</title><statement name="STACK"><block type="math_PushNumber" notchtype="TOP_BOTTOM_RIGHT" inline="false"><title name="NUM">20</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">0</title></block></value><next><block type="control_DoLoop" notchtype="Top_Bottom_Right" inline="false"><statement name="STACK"><block type="control_i" notchtype="TOP_BOTTOM_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">2</title><value name="NEXTWORD"><block type="math_Mod" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_TwoSlash" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="comment" notchtype="LEFT_RIGHT" inline="false"><title name="COMMENT">為何用I不用J,這是Forth有趣的特性,因為此時間點Return Stack只存在一個迴圈體</title></block></value></block></value></block></value></block></value><next><block type="math_PushNumber" notchtype="TOP_BOTTOM_RIGHT" inline="false"><title name="NUM">25</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">0</title></block></value><next><block type="control_DoLoop" notchtype="Top_Bottom_Right" inline="false"><statement name="STACK"><block type="stack_dup" notchtype="TOP_BOTTOM"><next><block type="procedures_callnoreturn" notchtype="TOP_BOTTOM_RIGHT" inline="false"><mutation name="psjObj"></mutation><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">25</title><value name="NEXTWORD"><block type="control_j" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_Multi" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="stack_rot" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="control_i" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_Add" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">20</title><value name="NEXTWORD"><block type="math_Multi" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">20</title><value name="NEXTWORD"><block type="math_PushNumber" notchtype="LEFT_RIGHT" inline="false"><title name="NUM">8</title><value name="NEXTWORD"><block type="processing_DrawRect" notchtype="LEFT_RIGHT" inline="false"><value name="NEXTWORD"><block type="comment" notchtype="LEFT_RIGHT" inline="false"><title name="COMMENT">此I非彼I</title></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></value></block></next></block></statement><next><block type="stack_drop" notchtype="TOP_BOTTOM"></block></next></block></next></block></next></block></statement></block></next></block></statement></block><block type="procedures_callnoreturn" notchtype="LEFT_RIGHT" inline="false" x="58" y="431"><mutation name="MyHighWord"></mutation><value name="NEXTWORD"><block type="comment" notchtype="LEFT_RIGHT" inline="false"><title name="COMMENT">JimmyScratchLab Demo</title></block></value></block></xml>

沒有留言:

張貼留言