Add items, values and keys methods to HyDict

Useful for macros, for example:

    (defmacro defn-checked [n x b]
      `(defn ~n [(unquote-splice (.keys x))]
        (print "Expecting:" (unquote-splice (.values x))) ~b))

    (defn-checked hello {name str age int}
      (print "Hello" name "you are" age))

    (hello "Godzilla" 60)

    ;; Expecting: <type 'str'> <type 'int'>
    ;; Hello Godzilla you are 60
This commit is contained in:
Brian McKenna 2014-01-25 15:30:03 -07:00
parent 429cba39b9
commit 0177541d9b

View File

@ -28,3 +28,12 @@ class HyDict(HyList):
def __repr__(self):
return "{%s}" % (" ".join([repr(x) for x in self]))
def keys(self):
return self[0::2]
def values(self):
return self[1::2]
def items(self):
return zip(self.keys(), self.values())