def k(s): '''creates a K object given its string representation >>> k('(1; 2 3; "abc")') k(""" (1 2 3 "abc") """) ''' try: return K(_ksk(s)) except kerr, e: raise kerr("%s in %s (vars:%s)" % (e, s, k("!.k")))
def __call__(self, *args): """K objects representing k functions can be called >>> f = k('{x+y}') >>> print f(1,2) 3 """ # XXX using undocumented feature - k functions have type 10 t = self.t #if t != 10: # raise TypeError("k object of type %d is not callable" % t) kk = K((self, K(args))) try: return K(_ksk('.', kk)) except kerr, e: raise kerr("%s\nvars: %s" % (e, k("!.k")))