infer,
JoyTypeError,
combinator_effect,
+ poly_combinator_effect,
)
@inscribe
-#@combinator_effect(_COMB_NUMS(), s7, s6)
+@combinator_effect(_COMB_NUMS(), s7, s6)
@FunctionWrapper
def b(stack, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), a1, s1)
@FunctionWrapper
def dupdip(stack, expression, dictionary):
'''
@inscribe
-#@combinator_effect(_COMB_NUMS(), s7, s6)
+@combinator_effect(_COMB_NUMS(), s7, s6)
@FunctionWrapper
def infra(stack, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), s7, s6, s5, s4)
@FunctionWrapper
def genrec(stack, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), s7, s6)
@FunctionWrapper
def map_(S, expression, dictionary):
'''
# return (q, (p, stack)), expression, dictionary
+def branch_true(stack, expression, dictionary):
+ (then, (else_, (flag, stack))) = stack
+ return stack, concat(then, expression), dictionary
+
+
+def branch_false(stack, expression, dictionary):
+ (then, (else_, (flag, stack))) = stack
+ return stack, concat(else_, expression), dictionary
+
+
@inscribe
+@poly_combinator_effect(_COMB_NUMS(), [branch_true, branch_false], b1, s7, s6)
@FunctionWrapper
def branch(stack, expression, dictionary):
'''
return stack, concat(then if flag else else_, expression), dictionary
+#FUNCTIONS['branch'] = CombinatorJoyType('branch', [branch_true, branch_false], 100)
+
+
##@inscribe
##@FunctionWrapper
##def ifte(stack, expression, dictionary):
@inscribe
+@combinator_effect(_COMB_NUMS(), a2, a1, s1)
@FunctionWrapper
def dipd(S, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1)
@FunctionWrapper
def dipdd(S, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), a1, s1)
@FunctionWrapper
def app1(S, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), a2, a1, s1)
@FunctionWrapper
def app2(S, expression, dictionary):
'''Like app1 with two items.
@inscribe
+@combinator_effect(_COMB_NUMS(), a3, a2, a1, s1)
@FunctionWrapper
def app3(S, expression, dictionary):
'''Like app1 with three items.
@inscribe
+@combinator_effect(_COMB_NUMS(), s7, s6)
@FunctionWrapper
def step(S, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), i1, s6)
@FunctionWrapper
def times(stack, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), b1, s6)
@FunctionWrapper
def loop(stack, expression, dictionary):
'''
@inscribe
+@combinator_effect(_COMB_NUMS(), a1, a2, s6, s7, s8)
@FunctionWrapper
def cmp_(stack, expression, dictionary):
'''
expression_to_string,
list_to_stack,
)
-# from joy.utils.types import (
-# AnyJoyType, A,
-# BooleanJoyType, B,
-# DEFS,
-# doc_from_stack_effect,
-# FloatJoyType, F,
-# JoyTypeError,
-# NumberJoyType, N,
-# StackJoyType, S,
-# _stacky,
-# _R,
-# relabel, delabel,
-# reify,
-# )
-
-'''Docstring for functions in Sphinx?'''
-
-
-def defs():
- '''
- Return a dict of FunctionJoyType instances to be used with ``infer()``.
- '''
-
- average = sum_ = product = min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))]
- flatten = [(((Ss[1], s1), s0), (s2, s0))]
+ average =
+ # sum_ =
+ # product =
+ # min_ = max_ = [(((Ns[1], s1), s0), (n0, s0))]
+ # flatten = [(((Ss[1], s1), s0), (s2, s0))]
return {
name.rstrip('_'): stack_effect
FUNCTIONS.update({
combo.__name__: CombinatorJoyType(combo.__name__, [combo], i)
for i, combo in enumerate((
- joy.library.b,
joy.library.concat_,
- joy.library.dip,
- joy.library.dipd,
- joy.library.dipdd,
- joy.library.dupdip,
- joy.library.i,
- joy.library.infra,
- joy.library._dictionary['nullary'],
- joy.library._dictionary['unary'],
- joy.library._dictionary['binary'],
- joy.library._dictionary['ternary'],
- joy.library._dictionary['quoted'],
- joy.library._dictionary['unquoted'],
- joy.library._dictionary['enstacken'],
joy.library._dictionary['disenstacken'],
joy.library.x,
))
def set_expectations():
- branch.expect = s7, (s6, (b1, s5))
+
loop.expect = s6, (b1, s5)
- i.expect = nullary.expect = x.expect = s7, s6
- dip.expect = dupdip.expect = s8, (a8, s7)
- dipd.expect = s8, (a8, (a7, s7))
- dipdd.expect = s8, (a8, (a7, (a6, s7)))
- b.expect = concat_.expect = infra.expect = s8, (s7, s6)
- set_expectations_of_definition(unary)
- set_expectations_of_definition(binary)
- set_expectations_of_definition(ternary)
- set_expectations_of_definition(quoted)
- set_expectations_of_definition(unquoted)
- set_expectations_of_definition(enstacken)
+# i.expect = nullary.expect = x.expect = s7, s6
+# dip.expect = dupdip.expect = s8, (a8, s7)
+# dipd.expect = s8, (a8, (a7, s7))
+# dipdd.expect = s8, (a8, (a7, (a6, s7)))
+ concat_.expect = s8, (s7, s6)
+# b.expect = infra.expect = s8, (s7, s6)
+ # set_expectations_of_definition(unary)
+ # set_expectations_of_definition(binary)
+ # set_expectations_of_definition(ternary)
+ # set_expectations_of_definition(quoted)
+ # set_expectations_of_definition(unquoted)
+ # set_expectations_of_definition(enstacken)
disenstacken.expect = (As[1], s1), s0
scope = globals().copy()
scope.update(FUNCTIONS)
def combinator_effect(number, *expect):
- def _combinator_effect(c):
- C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number)
- if expect: C.expect = __(*expect)
- return c
- return _combinator_effect
+ def _combinator_effect(c):
+ e = __(*expect) if expect else None
+ C = FUNCTIONS[c.name] = CombinatorJoyType(c.name, [c], number, e)
+ if expect: C.expect = __(*expect)
+ return c
+ return _combinator_effect
def show(DEFS):
##if __name__ == '__main__':
## show()
+
+def poly_combinator_effect(number, effect_funcs, *expect):
+ def _poly_combinator_effect(c):
+ e = __(*expect) if expect else None
+ FUNCTIONS[c.name] = CombinatorJoyType(c.name, effect_funcs, number, e)
+ return c
+ return _poly_combinator_effect
+
+#FUNCTIONS['branch'].expect = s7, (s6, (b1, s5))
+