• <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)  編輯 收藏 引用

            人妻少妇久久中文字幕| 久久国产免费| 久久精品国产影库免费看| 亚洲一区二区三区日本久久九| 国产精品一区二区久久精品无码 | 久久久久久狠狠丁香| 久久青青草原精品国产软件| 亚洲欧美成人综合久久久| 精品久久人人做人人爽综合| 亚洲AV无码久久精品蜜桃| 精品久久久久久国产三级| AAA级久久久精品无码片| 午夜精品久久久久久影视riav| 久久99免费视频| 日韩人妻无码精品久久免费一 | 久久国产乱子精品免费女| 久久精品国产99国产精品导航| 国产精品免费久久久久久久久 | 久久午夜无码鲁丝片午夜精品| 亚洲欧美成人综合久久久| 思思久久99热免费精品6| 久久国产精品免费一区| 国产欧美久久一区二区| 久久人人爽人人爽人人片av高请| 香港aa三级久久三级老师2021国产三级精品三级在 | 国产精品99久久久久久猫咪| 久久久久久久久久久久中文字幕| 中文字幕久久亚洲一区| 久久国产精品免费| 久久精品无码一区二区日韩AV| 色综合久久最新中文字幕| 99久久无码一区人妻a黑| 热re99久久6国产精品免费| 亚洲精品乱码久久久久久中文字幕| 久久受www免费人成_看片中文| 国产精品99久久久久久www| 久久精品国产清自在天天线| 久久久久亚洲精品无码网址| 久久精品国产黑森林| 香蕉99久久国产综合精品宅男自 | 久久精品欧美日韩精品|