Minor cleanup.
This commit is contained in:
parent
caa3cb9a1f
commit
eb42220b69
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright © 2014, 2015, 2017, 2018 Simon Forman
|
# Copyright © 2014-2020 Simon Forman
|
||||||
#
|
#
|
||||||
# This file is part of Thun
|
# This file is part of Thun
|
||||||
#
|
#
|
||||||
|
|
@ -23,9 +23,7 @@ functions. Its main export is a Python function initialize() that
|
||||||
returns a dictionary of Joy functions suitable for use with the joy()
|
returns a dictionary of Joy functions suitable for use with the joy()
|
||||||
function.
|
function.
|
||||||
'''
|
'''
|
||||||
from __future__ import print_function
|
|
||||||
from builtins import map, object, range, zip
|
from builtins import map, object, range, zip
|
||||||
from logging import getLogger
|
|
||||||
|
|
||||||
from inspect import getdoc
|
from inspect import getdoc
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
@ -34,8 +32,14 @@ from inspect import getmembers, isfunction
|
||||||
import operator, math
|
import operator, math
|
||||||
|
|
||||||
from .parser import text_to_expression, Symbol
|
from .parser import text_to_expression, Symbol
|
||||||
from .utils.stack import expression_to_string, list_to_stack, iter_stack, pick, concat
|
|
||||||
from .utils import generated_library as genlib
|
from .utils import generated_library as genlib
|
||||||
|
from .utils.stack import (
|
||||||
|
concat,
|
||||||
|
expression_to_string,
|
||||||
|
iter_stack,
|
||||||
|
list_to_stack,
|
||||||
|
pick,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
HELP_TEMPLATE = '''\
|
HELP_TEMPLATE = '''\
|
||||||
|
|
@ -141,6 +145,7 @@ size 0 swap [pop ++] step
|
||||||
sqr dup mul
|
sqr dup mul
|
||||||
step_zero 0 roll> step
|
step_zero 0 roll> step
|
||||||
swoncat swap concat
|
swoncat swap concat
|
||||||
|
tailrec [i] genrec
|
||||||
ternary unary [popop] dip
|
ternary unary [popop] dip
|
||||||
unary nullary popd
|
unary nullary popd
|
||||||
unquoted [i] dip
|
unquoted [i] dip
|
||||||
|
|
@ -886,7 +891,6 @@ def infra(stack, expression, dictionary):
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
#@combinator_effect(_COMB_NUMS(), s7, s6, s5, s4)
|
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def genrec(stack, expression, dictionary):
|
def genrec(stack, expression, dictionary):
|
||||||
'''
|
'''
|
||||||
|
|
@ -1028,18 +1032,6 @@ def primrec(stack, expression, dictionary):
|
||||||
# return (q, (p, stack)), expression, dictionary
|
# return (q, (p, stack)), expression, dictionary
|
||||||
|
|
||||||
|
|
||||||
def branch_true(stack, expression, dictionary):
|
|
||||||
# pylint: disable=unused-variable
|
|
||||||
(then, (else_, (flag, stack))) = stack
|
|
||||||
return stack, concat(then, expression), dictionary
|
|
||||||
|
|
||||||
|
|
||||||
def branch_false(stack, expression, dictionary):
|
|
||||||
# pylint: disable=unused-variable
|
|
||||||
(then, (else_, (flag, stack))) = stack
|
|
||||||
return stack, concat(else_, expression), dictionary
|
|
||||||
|
|
||||||
|
|
||||||
@inscribe
|
@inscribe
|
||||||
@FunctionWrapper
|
@FunctionWrapper
|
||||||
def branch(stack, expression, dictionary):
|
def branch(stack, expression, dictionary):
|
||||||
|
|
@ -1065,9 +1057,6 @@ def branch(stack, expression, dictionary):
|
||||||
return stack, concat(then if flag else else_, expression), dictionary
|
return stack, concat(then if flag else else_, expression), dictionary
|
||||||
|
|
||||||
|
|
||||||
#FUNCTIONS['branch'] = CombinatorJoyType('branch', [branch_true, branch_false], 100)
|
|
||||||
|
|
||||||
|
|
||||||
##@inscribe
|
##@inscribe
|
||||||
##@FunctionWrapper
|
##@FunctionWrapper
|
||||||
##def ifte(stack, expression, dictionary):
|
##def ifte(stack, expression, dictionary):
|
||||||
|
|
@ -1432,27 +1421,3 @@ add_aliases(_dictionary, ALIASES)
|
||||||
|
|
||||||
|
|
||||||
DefinitionWrapper.add_definitions(definitions, _dictionary)
|
DefinitionWrapper.add_definitions(definitions, _dictionary)
|
||||||
|
|
||||||
|
|
||||||
## product == 1 swap [*] step
|
|
||||||
## flatten == [] swap [concat] step
|
|
||||||
## pam == [i] map
|
|
||||||
## size == 0 swap [pop ++] step
|
|
||||||
## fork == [i] app2
|
|
||||||
## cleave == fork [popd] dip
|
|
||||||
## average == [sum 1.0 *] [size] cleave /
|
|
||||||
## gcd == 1 [tuck modulus dup 0 >] loop pop
|
|
||||||
## least_fraction == dup [gcd] infra [div] concat map
|
|
||||||
## *fraction == [uncons] dip uncons [swap] dip concat [*] infra [*] dip cons
|
|
||||||
## *fraction0 == concat [[swap] dip * [*] dip] infra
|
|
||||||
## down_to_zero == [0 >] [dup --] while
|
|
||||||
## range_to_zero == unit [down_to_zero] infra
|
|
||||||
## anamorphism == [pop []] swap [dip swons] genrec
|
|
||||||
## range == [0 <=] [1 - dup] anamorphism
|
|
||||||
## while == swap [nullary] cons dup dipd concat loop
|
|
||||||
## dupdipd == dup dipd
|
|
||||||
## tailrec == [i] genrec
|
|
||||||
## step_zero == 0 roll> step
|
|
||||||
## codireco == cons dip rest cons
|
|
||||||
## make_generator == [codireco] ccons
|
|
||||||
## ifte == [nullary not] dipd branch
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue