• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Life is Good.

            Enhance Tech and English
            隨筆 - 65, 文章 - 20, 評論 - 21, 引用 - 0
            數據加載中……

            Sorting out behavior of "IF / ELSE"

            Sorting out behavior of “IF / ELSE “

             

            The “ELSE” part of an IF statement is assumed in Lisp. So, if not careful, you may get unexpected behavior.

             

            Here is a recent change (in blue/gray highlight) someone pushed up to Perforce for one of the  lisp files:

               (setq x nil)

              (setq cnt 0)

              (while (< cnt (length ss))

                (if (nth cnt ss)

                  (setq en (handent (nth cnt ss)))

                  (if en

                    (progn

                      (setq x value1)

                      (if (not x)

                        (setq x value2)

                      )

                    )

                  )

                )

             

            This looks pretty benign… but it will likely cause a regression.

             

            To better see this problem, here is the same code with an “ELSE” comment inserted where end of the “True” part of the IF statement ends and the assumed “else” part of the if statement begins:

             

               (setq x nil)

              (setq cnt 0)

              (while (< cnt (length ss))

                (if (nth cnt ss)

                  (setq en (handent (nth cnt ss)))

                             ; ELSE

                  (if en

                    (progn

                      (setq x value1)

                      (if (not x)

                        (setq x value2)

                      )

                    )

                  )

                )

             

            So, here’s what will happen. The IF statement checks (nth cnt ss) to see if it is non-nil. If it is non-nil, then it fills variable “en” with the converted handle value in (nth cnt ss). Then it exits the IF statement. But, if (nth cnt ss) is nil, then a second IF statement checks undefined / uninitialized variable “en” and, if it happens to be non-nil, tries to do something with it. Likely it will do something not expected or desired.

             

            Grouping lines of code in an IF statement

             

            A better way to set up this IF/ELSE statement is probably something like this:

             

              (setq x nil)

              (setq cnt 0)

              (while (< cnt (length ss))

                (if (nth cnt ss)

                  (progn

                    (setq en (handent (nth cnt ss)))

                    (if en

                      (progn

                        (setq x value1)

                        (if (not x)

                          (setq x value2)

                        )

                      )

                    )

                  )

                )

             

            The beginning “(progn” and ending “)” to balance it groups all of the in-between lines of code to be executed for the “True” part of the IF statement. This is probably what needs to happen here.

             

            So, two things to watch for which may help avoid creating new regressions:

            1.       Go ahead and show the “; ELSE” comment in an IF statement when both conditions are being coded up.

            2.       Use the “(progn “ flag to group two or more lines of code together that need to execute for a single condition of the IF statement

            posted on 2008-08-08 13:46 Mike Song 閱讀(107) 評論(0)  編輯 收藏 引用

            久久最近最新中文字幕大全| 亚洲欧美成人综合久久久 | 777米奇久久最新地址| 亚洲国产精品综合久久网络| 久久这里只有精品久久| 99精品久久精品一区二区| 久久精品国产亚洲AV嫖农村妇女| 亚洲中文字幕伊人久久无码 | 久久精品国产日本波多野结衣 | 久久久久香蕉视频| 久久久久久A亚洲欧洲AV冫 | 日韩va亚洲va欧美va久久| 久久精品国产亚洲一区二区三区| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 亚洲va中文字幕无码久久 | 久久国产影院| 四虎影视久久久免费观看| 久久婷婷五月综合成人D啪| 久久久亚洲AV波多野结衣| 7777精品伊人久久久大香线蕉| 久久久精品人妻一区二区三区蜜桃| 精品久久亚洲中文无码| 精品国产VA久久久久久久冰 | 欧美精品丝袜久久久中文字幕| 亚洲欧美成人久久综合中文网| 久久www免费人成看片| 99久久久精品| 欧美色综合久久久久久| 99久久精品免费看国产一区二区三区 | 77777亚洲午夜久久多喷| 国产女人aaa级久久久级| 伊人久久五月天| 久久久久夜夜夜精品国产| 最新久久免费视频| 久久精品国产亚洲一区二区| 久久青青草原亚洲av无码| 婷婷久久久亚洲欧洲日产国码AV| 91麻豆精品国产91久久久久久| 精品无码久久久久国产动漫3d| 日本精品久久久久中文字幕| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 |