示例#1
0
    def equ_numstr(self):
        """( y x -- y=x? )
        push 1 if a number is equal to the sum of the characters in a string"""
        y, x = self.popn()
        if allof(isstr(y), isnum(x)):
            self.push(CatClutter.bool2int(x == CatClutter.strsum(y)))

        elif allof(isnum(y), isstr(x)):
            self.push(CatClutter.bool2int(y == CatClutter.strsum(x)))

        else:
            CatLogger.Crit("unexpected types for equ_numstr")
示例#2
0
 def get_exact(self):
     """( x -- y )
     get exactly x bytes of stdin, and push them as a string"""
     x = self.pop()
     if isnone(x):
         return
     if not isnum(x):
         CatLogger.Crit("need a number of characters to get not " + repr(type(x)))
         return
     from input_constrain import thismany
     self.push(thismany(x))
示例#3
0
 def get_until_not(self):
     """( -- y )
     read stdin until !char"""
     x = self.pop()
     if isnone(x):
         return
     elif isnum(x):
         x = chr(x)
     elif isstr(x):
         x = x[0]
     else:
         CatLogger.Crit("bad type for get_until_not; ignoring")
         return
     from input_constrain import until_not
     self.push(until_not(x))
示例#4
0
 def get_until(self):
     """( x -- y )
     get stdin until the character with codepoint x is read, pushing to y"""
     x = self.pop()
     if isnone(x):
         return
     elif isnum(x):
         x = chr(x)
     elif isstr(x):
         x = x[0]
     else:
         CatLogger.Crit("bad type for get_until_not; ignoring")
         return
     from input_constrain import until
     self.push(until(x))