Scheme: Fix evaluation of nested functions.
parent
ac87d9fb36
commit
efeef90c5b
|
@ -30,6 +30,7 @@
|
|||
|
||||
import ast
|
||||
import operator
|
||||
import functools
|
||||
import collections
|
||||
|
||||
import supybot.utils as utils
|
||||
|
@ -44,6 +45,12 @@ _ = PluginInternationalization('Scheme')
|
|||
class SchemeException(Exception):
|
||||
pass
|
||||
|
||||
def eval_argument(arg, env):
|
||||
if isinstance(arg, list):
|
||||
return eval_scheme(arg, env)
|
||||
else:
|
||||
return env[arg] if arg in env else ast.literal_eval(arg)
|
||||
|
||||
def schemify_math(f):
|
||||
# Makes a two-arguments function an *args function, with correct
|
||||
# type parsing.
|
||||
|
@ -53,8 +60,7 @@ def schemify_math(f):
|
|||
else:
|
||||
return f(args[0], args[1])
|
||||
def newf(tree, env):
|
||||
return rec(map(lambda x:(env[x] if x in env else ast.literal_eval(x)),
|
||||
tree[1:]))
|
||||
return rec(map(functools.partial(eval_argument, env=env), tree[1:]))
|
||||
return newf
|
||||
|
||||
# Add some math operators
|
||||
|
|
|
@ -45,5 +45,6 @@ class SchemeTestCase(PluginTestCase):
|
|||
def testEval(self):
|
||||
self.assertResponse('scheme (+ 11 12)', '23')
|
||||
self.assertResponse('scheme (+ 5 4 2)', '11')
|
||||
self.assertResponse('scheme (+ 5 (* 5 2))', '15')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
|
Loading…
Reference in New Issue