We don't need floor if we have only ints.

Id is too easy as a definition.

divmod is cool.
This commit is contained in:
Simon Forman 2022-09-12 16:38:14 -07:00
parent 1e3b2f76bb
commit aad2da35cf
2 changed files with 23 additions and 28 deletions

View File

@ -7,33 +7,6 @@ ALIASES = (
('id', [u'']), ('id', [u'']),
) )
def floor(n):
return int(math.floor(n))
floor.__doc__ = math.floor.__doc__
@inscribe
@SimpleFunctionWrapper
def divmod_(S):
'''
divmod(x, y) -> (quotient, remainder)
Return the tuple (x//y, x%y). Invariant: q * y + r == x.
'''
y, (x, stack) = S
q, r = divmod(x, y)
return r, (q, stack)
@inscribe
@SimpleFunctionWrapper
def id_(stack):
'''The identity function.'''
return stack
# #
# § Combinators # § Combinators
# #

View File

@ -1730,6 +1730,28 @@ def pm(stack):
return m, (p, stack) return m, (p, stack)
@inscribe
@SimpleFunctionWrapper
def divmod_(S):
'''
Similarly to pm ("Plus or minus") this function computes
both the
::
a b divmod
---------------------
a b div a b mod
---------------------
q r
Where: q * b + r == a
'''
y, (x, stack) = S
q, r = divmod(x, y)
return r, (q, stack)
@inscribe @inscribe
def sharing(stack, expression, dictionary): def sharing(stack, expression, dictionary):
'''Print redistribution information.''' '''Print redistribution information.'''
@ -2038,7 +2060,7 @@ S_cond = Symbol('cond')
def cond(stack, expr, dictionary): def cond(stack, expr, dictionary):
''' '''
This combinator works like a case statement. It expects a single quote This combinator works like a case statement. It expects a single quote
on the stack that must contain zero or more condition quotes and a on the stack that must contain zero or more condition quotes and a
default quote. Each condition clause should contain a quoted predicate default quote. Each condition clause should contain a quoted predicate
followed by the function expression to run if that predicate returns followed by the function expression to run if that predicate returns
true. If no predicates return true the default function runs. true. If no predicates return true the default function runs.