From 63aa7d1388438aec90faa794f28e7786174b118c Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 29 Jan 2012 15:37:45 +0000 Subject: add is heap empty block --- (limited to 'plugins/turtle_blocks_extras') diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index 9369d80..0ab049a 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -435,6 +435,16 @@ last-out heap)')) define_logo_function('tapop', 'to tapop\rif emptyp :taheap [stop]\r\ make "tmp first :taheap\rmake "taheap butfirst :taheap\routput :tmp\rend\r') + primitive_dictionary['isheapempty'] = self._prim_is_heap_empty + palette.add_block('isheapempty', + style='box-style', + label=_('empty heap?'), + prim_name='isheapempty', + value_block=True, + help_string=_('returns True if heap is empty')) + self.tw.lc.def_prim('isheapempty', 0, + lambda self: primitive_dictionary['isheapempty']()) + primitive_dictionary['print'] = self._prim_print palette.add_block('comment', style='basic-style-1arg', @@ -972,6 +982,13 @@ bullets')) self.tw.lc.stop_logo() raise logoerror("#notanumber") + def _prim_is_heap_empty(self): + """ is FILO empty? """ + if len(self.tw.lc.heap) == 0: + return 1 + else: + return 0 + def _prim_pop(self): """ Pop value off of FILO """ if len(self.tw.lc.heap) == 0: -- cgit v0.9.1