“Dead method context” error in a function

后端 未结 2 651
不思量自难忘°
不思量自难忘° 2021-01-23 01:32

I am trying to write a isBinary function that checks sent line if it has any non-printable characters (integer value outside range 0-127):

isBinary         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 02:16

    Following standalone method/block code works by creating a return variable whose value is manipulated in loop if unprintable character is found. The loop is then exited:

    isBinary := [ :sline |            "WORKS"
        'Reached isBinary fn: ' display.
        ret := false.                 "return variable initialized to false"
        sline do: [ :char |           "loop for each character in sent line"
            i := char asInteger.      "convert to integer"
            i > 127                   "check if printable"
            ifTrue: [ret := true. exit]].   "ret becomes true if found unprintable; does not work if ^ symbol is used"  
        ret].            "if not found above, ret remains false; ret is returned value"
    

    Above works without creating a class as desired by OP (me!).

提交回复
热议问题