• <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 閱讀(109) 評論(0)  編輯 收藏 引用

            2021精品国产综合久久| 国产日韩久久免费影院| 亚洲女久久久噜噜噜熟女| 国内精品久久久久久久久电影网| 狠狠色噜噜色狠狠狠综合久久 | 日韩精品无码久久一区二区三| 亚洲国产视频久久| 久久精品国产久精国产思思| 久久亚洲国产精品五月天婷| 久久综合九色综合网站| 久久精品国产只有精品66| 精品国产乱码久久久久久1区2区| 久久精品中文字幕有码| www.久久热.com| 亚洲午夜久久久影院| 色偷偷88欧美精品久久久 | 中文字幕久久波多野结衣av| 国产精品久久久久久一区二区三区| 一本久久a久久精品综合香蕉| 久久久青草久久久青草| 亚洲国产精品无码久久一线| 一级做a爰片久久毛片看看| 国产成人精品久久一区二区三区av| 亚洲精品乱码久久久久久按摩| 日本精品久久久久久久久免费| 久久久久久狠狠丁香| 国产三级久久久精品麻豆三级| 久久这里的只有是精品23| 精品国产综合区久久久久久 | 久久精品国产亚洲AV大全| 久久久久久精品免费看SSS| 色综合久久88色综合天天 | 国产精品久久久久一区二区三区| 狠狠色丁香久久综合五月| 久久久久亚洲AV无码专区体验| 婷婷五月深深久久精品| 久久久久久午夜成人影院| 浪潮AV色综合久久天堂| 激情伊人五月天久久综合| 嫩草影院久久国产精品| 国产精品久久久久久久午夜片 |