Example #1
0
from langner import build

input = """
    (x.sex=="f", y.sex=="m", x.score == y.score) -> (print(x.name + " dates " + y.name));
"""

strat = build(input)

# Girls:
strat.add_to_gos({"name": "Kate", "sex": "f", "score": 3})
strat.add_to_gos({"name": "Meg", "sex": "f", "score": 7})
strat.add_to_gos({"name": "Sandy", "sex": "f", "score": 10})

# Boys:
strat.add_to_gos({"name": "John", "sex": "m", "score": 3})
strat.add_to_gos({"name": "Ben", "sex": "m", "score": 7})
strat.add_to_gos({"name": "Alex", "sex": "m", "score": 10})

strat.run()
Example #2
0
from langner import build

input = '''
    (x.sex=="f", y.sex=="m", x.score == y.score) -> (print(x.name + " dates " + y.name));
'''

strat = build(input)

# Girls:
strat.add_to_gos({"name":"Kate", "sex":"f", "score":3})
strat.add_to_gos({"name":"Meg", "sex":"f", "score":7})
strat.add_to_gos({"name":"Sandy", "sex":"f", "score":10})

# Boys:
strat.add_to_gos({"name":"John", "sex":"m", "score":3})
strat.add_to_gos({"name":"Ben", "sex":"m", "score":7})
strat.add_to_gos({"name":"Alex", "sex":"m", "score":10})

strat.run()
Example #3
0
from langner import build

input = '''
    (o("A"), o("B")) -> (o("C"), o("D"));
    (o("F"), o("G")) -> (o("G"), o("H"));
    (True)->(print("-----------------"));
'''


def o(v):
    print v
    return True


strat = build(input, functions=[o])
strat.run()
Example #4
0
            kid.sex=sex(),
            kid.name=name(kid.sex, x.name, y.name),
            kid.mom=x,
            kid.dad=y,
            print(x.name + " " + y.name + " are having kid " + kid.name + ".")
    );
    (True)->(print("-------"));
'''

def sex():
    return functions.choice(["f","m"])

def name(sex, mom, dad):
    if "f" == sex:
        return mom + " Jr."
    return dad + " Jr."

strat = build(input, functions={"sex":sex, "name":name})

# Girls:
strat.add_to_gos({"name":"Kate", "sex":"f"})
strat.add_to_gos({"name":"Meg", "sex":"f"})
strat.add_to_gos({"name":"Sandy", "sex":"f"})

# Boys:
strat.add_to_gos({"name":"John", "sex":"m"})
strat.add_to_gos({"name":"Ben", "sex":"m"})
strat.add_to_gos({"name":"Alex", "sex":"m"})

strat.run()
Example #5
0
            kid.dad=y,
            print(x.name + " " + y.name + " are having kid " + kid.name + ".")
    );
    (True)->(print("-------"));
'''


def sex():
    return functions.choice(["f", "m"])


def name(sex, mom, dad):
    if "f" == sex:
        return mom + " Jr."
    return dad + " Jr."


strat = build(input, functions={"sex": sex, "name": name})

# Girls:
strat.add_to_gos({"name": "Kate", "sex": "f"})
strat.add_to_gos({"name": "Meg", "sex": "f"})
strat.add_to_gos({"name": "Sandy", "sex": "f"})

# Boys:
strat.add_to_gos({"name": "John", "sex": "m"})
strat.add_to_gos({"name": "Ben", "sex": "m"})
strat.add_to_gos({"name": "Alex", "sex": "m"})

strat.run()
Example #6
0
from langner import build
from random import random

input = '''
    (True) -> (print(random()));
'''

strat = build(input, functions=[random])
strat.run()
Example #7
0
from langner import build

input = '''
    (o("A"), o("B")) -> (o("C"), o("D"));
    (o("F"), o("G")) -> (o("G"), o("H"));
    (True)->(print("-----------------"));
'''

def o(v):
    print v
    return True

strat = build(input, functions=[o])
strat.run()