Beispiel #1
0
def Alias(newname, oldname):
    """Creates an alias for an existing element in a struct

    :param newname: the new name
    :param oldname: the name of an existing element
    """
    return Value(newname, lambda ctx: ctx[oldname])
Beispiel #2
0
def If(predicate, subcon, elsevalue=None):
    """An if-then conditional construct: if the predicate indicates True,
    subcon will be used; otherwise, `elsevalue` will be returned instead.

    :param predicate: a function taking the context as an argument and returning True or False
    :param subcon: the subcon that will be used if the predicate returns True
    :param elsevalue: the value that will be used should the predicate return False.
                      by default this value is None.
    """
    return IfThenElse(subcon.name, predicate, subcon,
                      Value("elsevalue", lambda ctx: elsevalue))
Beispiel #3
0
def Alias(newname, oldname):
    """creates an alias for an existing element in a struct
    * newname - the new name
    * oldname - the name of an existing element
    """
    return Value(newname, lambda ctx: ctx[oldname])