Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-08-12 15:09:46 (GMT)
committer Marion <marion.zepf@gmail.com>2013-08-12 15:09:46 (GMT)
commit6edade53f3b0bc23adfd215a67770aec4a726d62 (patch)
tree151f42b00a0216c17848d2ea0badb30ea0f1d2d7
parent41e58dde24b5a93496edf30b35ff963fc53d48b9 (diff)
add Primitives for the 'less than' and 'greater than' blocks
-rw-r--r--TurtleArt/tabasics.py16
-rw-r--r--TurtleArt/taconstants.py28
-rw-r--r--TurtleArt/taprimitive.py14
3 files changed, 48 insertions, 10 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py
index 7702ad5..7a1d957 100644
--- a/TurtleArt/tabasics.py
+++ b/TurtleArt/tabasics.py
@@ -721,7 +721,6 @@ output (random (:max - :min)) + :min\nend\n')
help_string=_('used as numeric input in mathematic \
operators'))
- primitive_dictionary['more'] = self._prim_more
palette.add_block('greater2',
style='compare-porch-style',
label=' >',
@@ -730,11 +729,11 @@ operators'))
prim_name='greater?',
logo_command='greater?',
help_string=_('logical greater-than operator'))
- self.tw.lc.def_prim(
- 'greater?', 2,
- lambda self, x, y: primitive_dictionary['more'](x, y))
+ self.tw.lc.def_prim('greater?', 2,
+ Primitive(Primitive.greater,
+ slot_wrappers={0: self.prim_cache["convert_for_cmp"],
+ 1: self.prim_cache["convert_for_cmp"]}))
- primitive_dictionary['less'] = self._prim_less
palette.add_block('less2',
style='compare-porch-style',
label=' <',
@@ -743,10 +742,11 @@ operators'))
prim_name='less?',
logo_command='less?',
help_string=_('logical less-than operator'))
- self.tw.lc.def_prim(
- 'less?', 2, lambda self, x, y: primitive_dictionary['less'](x, y))
+ self.tw.lc.def_prim('less?', 2,
+ Primitive(Primitive.less,
+ slot_wrappers={0: self.prim_cache["convert_for_cmp"],
+ 1: self.prim_cache["convert_for_cmp"]}))
- primitive_dictionary['equal'] = self._prim_equal
palette.add_block('equal2',
style='compare-style',
label='=',
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py
index 4648993..ba0b5a7 100644
--- a/TurtleArt/taconstants.py
+++ b/TurtleArt/taconstants.py
@@ -125,7 +125,33 @@ class Color(object):
else:
return False
- # TODO implement addition
+ def __lt__(self, other):
+ """ A Color is less than
+ * another Color whose name appears earlier in the alphabet
+ * a number that is less than int(self)
+ * a string that appears before the underscore in the ASCII table """
+ if isinstance(other, Color):
+ return str(self) < str(other)
+ elif isinstance(other, (int, float, long)):
+ return int(self) < other
+ elif isinstance(other, basestring):
+ return '_' + str(self) < other
+ else:
+ return False
+
+ def __gt__(self, other):
+ """ A Color is greater than
+ * another Color whose name appears later in the alphabet
+ * a number that is greater than int(self)
+ * a string that appears after the underscore in the ASCII table """
+ if isinstance(other, Color):
+ return str(self) > str(other)
+ elif isinstance(other, (int, float, long)):
+ return int(self) > other
+ elif isinstance(other, basestring):
+ return '_' + str(self) > other
+ else:
+ return False
def is_gray(self):
""" Return True iff this color is white, gray, or black, i.e. if its
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index baaa9e0..364ff11 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -65,7 +65,9 @@ class Primitive(object):
'and_': ast.And,
'or_': ast.Or,
'not_': ast.Not,
- 'equals': ast.Eq}
+ 'equals': ast.Eq,
+ 'less': ast.Lt,
+ 'greater': ast.Gt}
def __init__(self, func, constant_args=None, slot_wrappers=None,
call_afterwards=None, call_me=True, export_me=True):
@@ -683,6 +685,16 @@ class Primitive(object):
""" Return arg1 == arg2 """
return arg1 == arg2
+ @staticmethod
+ def less(arg1, arg2):
+ """ Return arg1 < arg2 """
+ return arg1 < arg2
+
+ @staticmethod
+ def greater(arg1, arg2):
+ """ Return arg1 > arg2 """
+ return arg1 > arg2
+
class PrimitiveCall(Primitive):