Пример #1
0
 def test_ksk(self):
     k = _ksk("1+2")
     p = _Ki(k)
     self.failIf(p != 3, 'got %s, expected 3' % p)
     k = _ksk("{x+y}", _gk(self.f, self.i))
     p = _Kf(k)
     self.failIf(p != 10.0, 'got %s, expected 10.0' % p)
     self.failUnlessRaises(kerr, _ksk, ')')
Пример #2
0
 def test_ksk(self):
     k = _ksk("1+2")
     p = _Ki(k)
     self.failIf(p != 3, 'got %s, expected 3' % p)
     k = _ksk("{x+y}", _gk(self.f, self.i))
     p = _Kf(k)
     self.failIf(p != 10.0, 'got %s, expected 10.0' % p)
     self.failUnlessRaises(kerr, _ksk, ')')
Пример #3
0
 def test_dict(self):
     k = _ksk(".((`a;1;.,(`z;42));(`b;2))")
     a = _Ki(k['a'])
     self.failIf(a != 1, 'got "%s" instead of 1' % a)
     k['a'] = _gi(2)
     a = _Ki(k['a'])
     self.failIf(a != 2, 'got "%s" instead of 2' % a)
     z = _Ki(k['a.']['z'])
     self.failIf(z != 42, 'attribute - got %s, expected 42')
Пример #4
0
 def test_dict(self):
     k = _ksk(".((`a;1;.,(`z;42));(`b;2))")
     a = _Ki(k['a'])
     self.failIf(a != 1, 'got "%s" instead of 1' % a)
     k['a'] = _gi(2)
     a = _Ki(k['a'])
     self.failIf(a != 2, 'got "%s" instead of 2' % a)
     z = _Ki(k['a.']['z'])
     self.failIf(z != 42, 'attribute - got %s, expected 42')
Пример #5
0
Файл: K.py Проект: plusxp/kx-1
def _gendict(pyo):
    values = [K(x) for x in pyo.values()]
    keys = pyo.keys()
    # k function to translate a list of values
    # to a k dictionary
    kfexpr = ('{[%s] .(%s)}' % (';'.join(keys), ';'.join(
        ['(`%(key)s;%(key)s)' % {
            'key': key
        } for key in keys])))
    return K(_ksk(kfexpr, K(values)))
Пример #6
0
Файл: K.py Проект: kevinarpe/kx
def _gendict(pyo):
    values = [K(x) for x in pyo.values()]
    keys = pyo.keys()
    # k function to translate a list of values
    # to a k dictionary
    kfexpr = ('{[%s] .(%s)}'
              % (';'.join(keys),
                 ';'.join(['(`%(key)s;%(key)s)' % {'key': key}
                           for key in keys])))
    return K(_ksk(kfexpr, K(values)))
Пример #7
0
Файл: K.py Проект: plusxp/kx-1
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")))
Пример #8
0
Файл: K.py Проект: kevinarpe/kx
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")))
Пример #9
0
Файл: K.py Проект: plusxp/kx-1
 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")))
Пример #10
0
Файл: K.py Проект: kevinarpe/kx
 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")))
Пример #11
0
def k(s): return _ksk(s)

class nk20TestCase(unittest.TestCase):
Пример #12
0
 def testDictionaryConversionFromK(self):
     # just test that we don't crash for now
     d = _ksk('.((`a; 1;);(`b; 2;.,(`c;4)))')
     a =  _ktoarray(_ktoarray(d)[1])
Пример #13
0
 def testDictionaryConversionFromK(self):
     # just test that we don't crash for now
     d = _ksk('.((`a; 1;);(`b; 2;.,(`c;4)))')
     a = _ktoarray(_ktoarray(d)[1])
Пример #14
0
def k(s):
    return _ksk(s)