divmod
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:
parent
1e3b2f76bb
commit
aad2da35cf
|
|
@ -7,33 +7,6 @@ ALIASES = (
|
|||
('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
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1730,6 +1730,28 @@ def pm(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
|
||||
def sharing(stack, expression, dictionary):
|
||||
'''Print redistribution information.'''
|
||||
|
|
@ -2038,7 +2060,7 @@ S_cond = Symbol('cond')
|
|||
def cond(stack, expr, dictionary):
|
||||
'''
|
||||
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
|
||||
followed by the function expression to run if that predicate returns
|
||||
true. If no predicates return true the default function runs.
|
||||
|
|
|
|||
Loading…
Reference in New Issue