Author: Juergen Boemmels <boemm...@web.de> Branch: Changeset: r33:82753c10ee59 Date: 2011-12-29 22:37 +0100 http://bitbucket.org/pypy/lang-scheme/changeset/82753c10ee59/
Log: Implement all numerical comparisions (< <= > >=) diff --git a/scheme/procedure.py b/scheme/procedure.py --- a/scheme/procedure.py +++ b/scheme/procedure.py @@ -94,9 +94,7 @@ Mul = create_op_class('*', '', "Mul", 1) Div = create_op_class('/', '1 /', "Div") -class Equal(W_Procedure): - _symbol_name = "=" - +class NumberComparison(W_Procedure): def procedure(self, ctx, lst): if len(lst) < 2: return W_Boolean(True) @@ -109,12 +107,43 @@ if not isinstance(arg, W_Number): raise WrongArgType(arg, "Number") - if prev.to_number() != arg.to_number(): + if not self.relation(prev.to_number(), arg.to_number()): return W_Boolean(False) prev = arg return W_Boolean(True) +class Equal(NumberComparison): + _symbol_name = "=" + + def relation(self, a, b): + return a == b + +class LessThen(NumberComparison): + _symbol_name = "<" + + def relation(self, a, b): + return a < b + +class LessEqual(NumberComparison): + _symbol_name = "<=" + + def relation(self, a, b): + return a <= b + +class GreaterThen(NumberComparison): + _symbol_name = ">" + + def relation(self, a, b): + return a > b + +class GreaterEqual(NumberComparison): + _symbol_name = ">=" + + def relation(self, a, b): + return a >= b + + class List(W_Procedure): _symbol_name = "list" diff --git a/scheme/test/test_eval.py b/scheme/test/test_eval.py --- a/scheme/test/test_eval.py +++ b/scheme/test/test_eval.py @@ -199,6 +199,21 @@ py.test.raises(WrongArgType, eval_noctx, "(= 'a 1)") + w_bool = eval_noctx("(< 1 2 3)") + assert w_bool.to_boolean() is True + + w_bool = eval_noctx("(< 1 3 2)") + assert w_bool.to_boolean() is False + + w_bool = eval_noctx("(> 3 2 1)") + assert w_bool.to_boolean() is True + + w_bool = eval_noctx("(<= 1 1 2 2 3)") + assert w_bool.to_boolean() is True + + w_bool = eval_noctx("(>= 3 3 1)") + assert w_bool.to_boolean() is True + def test_comparison_heteronums(): w_bool = eval_noctx("(= 1 1.0 1.1)") assert w_bool.to_boolean() is False @@ -839,4 +854,10 @@ py.test.raises(WrongArgType, eval_, ctx, "(append 'a '())") py.test.raises(WrongArgType, eval_, ctx, "(append 1 2 3)") - py.test.raises(WrongArgType, eval_, ctx, "(append! (cons 1 2) '(3 4))") \ No newline at end of file + py.test.raises(WrongArgType, eval_, ctx, "(append! (cons 1 2) '(3 4))") + +def test_not(): + assert not eval_noctx("(not #t)").to_boolean() + assert eval_noctx("(not #f)").to_boolean() + assert not eval_noctx("(not '())").to_boolean() + assert not eval_noctx("(not 0)").to_boolean() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit