def apply_levelspec(self, expr, rules, ls, evaluation, options): 'Replace[expr_, rules_, Optional[Pattern[ls, _?LevelQ], {0}], OptionsPattern[Replace]]' try: rules, ret = create_rules(rules, expr, 'Replace', evaluation) if ret: return rules heads = self.get_option(options, 'Heads', evaluation).is_true() result, applied = expr.apply_rules( rules, evaluation, level=0, options={ 'levelspec': python_levelspec(ls), 'heads': heads}) return result except InvalidLevelspecError: evaluation.message('General', 'level', ls)
def apply_level(self, f, expr, ls, evaluation, options={}): 'Map[f_, expr_, ls_?LevelQ:{1}, OptionsPattern[Map]]' try: start, stop = python_levelspec(ls) except InvalidLevelspecError: evaluation.message('Map', 'level', ls) return def callback(level): return Expression(f, level) heads = self.get_option(options, 'Heads', evaluation).is_true() result, depth = walk_levels(expr, start, stop, heads=heads, callback=callback) return result
def apply_level(self, f, expr, ls, evaluation, options={}): 'MapIndexed[f_, expr_, ls_?LevelQ:{1}, OptionsPattern[MapIndexed]]' try: start, stop = python_levelspec(ls) except InvalidLevelspecError: evaluation.message('MapIndexed', 'level', ls) return def callback(level, pos): return Expression(f, level, Expression('List', *(Integer(p) for p in pos))) heads = self.get_option(options, 'Heads', evaluation).is_true() result, depth = walk_levels(expr, start, stop, heads=heads, callback=callback, include_pos=True) return result
def apply_level(self, f, expr, ls, evaluation, options={}): """Map[f_, expr_, Optional[Pattern[ls, _?LevelQ], {1}], OptionsPattern[Map]]""" try: start, stop = python_levelspec(ls) except InvalidLevelspecError: evaluation.message("Map", "level", ls) return def callback(level): return Expression(f, level) heads = self.get_option(options, "Heads", evaluation).is_true() result, depth = walk_levels(expr, start, stop, heads=heads, callback=callback) return result
def apply_level(self, f, expr, ls, evaluation, options={}): """MapIndexed[f_, expr_, Optional[Pattern[ls, _?LevelQ], {1}], OptionsPattern[MapIndexed]]""" try: start, stop = python_levelspec(ls) except InvalidLevelspecError: evaluation.message("MapIndexed", "level", ls) return def callback(level, pos): return Expression(f, level, Expression("List", *[Integer(p) for p in pos])) heads = self.get_option(options, "Heads", evaluation).is_true() result, depth = walk_levels(expr, start, stop, heads=heads, callback=callback, include_pos=True) return result
def apply(self, f, expr, ls, evaluation, options={}): 'Apply[f_, expr_, ls_?LevelQ:{0}, OptionsPattern[Apply]]' try: start, stop = python_levelspec(ls) except InvalidLevelspecError: evaluation.message('Apply', 'level', ls) return def callback(level): if level.is_atom(): return level else: return Expression(f, *level.leaves) heads = self.get_option(options, 'Heads', evaluation).is_true() result, depth = walk_levels(expr, start, stop, heads=heads, callback=callback) return result
def apply_level(self, f, expr, ls, evaluation, options={}): '''Scan[f_, expr_, Optional[Pattern[ls, _?LevelQ], {1}], OptionsPattern[Map]]''' try: start, stop = python_levelspec(ls) except InvalidLevelspecError: evaluation.message('Map', 'level', ls) return def callback(level): Expression(f, level).evaluate(evaluation) return level heads = self.get_option(options, 'Heads', evaluation).is_true() result, depth = walk_levels( expr, start, stop, heads=heads, callback=callback) return Symbol('Null')
def apply(self, expr, test, level, evaluation): "%(name)s[expr_, test_, level_]" try: start, stop = python_levelspec(level) except InvalidLevelspecError: evaluation.message("Level", "level", level) return def callback(node): self._short_circuit(Expression(test, node).evaluate(evaluation).is_true()) return node try: walk_levels(expr, start, stop, callback=callback) except _ShortCircuit as e: return e.result return self._no_short_circuit()
def apply(self, f, expr, ls, evaluation, options={}): """Apply[f_, expr_, Optional[Pattern[ls, _?LevelQ], {0}], OptionsPattern[Apply]]""" try: start, stop = python_levelspec(ls) except InvalidLevelspecError: evaluation.message("Apply", "level", ls) return def callback(level): if level.is_atom(): return level else: return Expression(f, *level.leaves) heads = self.get_option(options, "Heads", evaluation).is_true() result, depth = walk_levels(expr, start, stop, heads=heads, callback=callback) return result
def apply_levelspec(self, expr, rules, ls, evaluation, options): 'Replace[expr_, rules_, Optional[Pattern[ls, _?LevelQ], {0}], OptionsPattern[Replace]]' try: rules, ret = create_rules(rules, expr, 'Replace', evaluation) if ret: return rules heads = self.get_option(options, 'Heads', evaluation).is_true() result, applied = expr.apply_rules(rules, evaluation, level=0, options={ 'levelspec': python_levelspec(ls), 'heads': heads }) return result except InvalidLevelspecError: evaluation.message('General', 'level', ls) except PatternError: evaluation.message('Replace', 'reps', rules)
def apply_levelspec(self, expr, rules, ls, evaluation, options): "Replace[expr_, rules_, Optional[Pattern[ls, _?LevelQ], {0}], OptionsPattern[Replace]]" try: rules, ret = create_rules(rules, expr, "Replace", evaluation) if ret: return rules heads = self.get_option(options, "Heads", evaluation).is_true() result, applied = expr.apply_rules( rules, evaluation, level=0, options={ "levelspec": python_levelspec(ls), "heads": heads }, ) return result except InvalidLevelspecError: evaluation.message("General", "level", ls) except PatternError: evaluation.message("Replace", "reps", rules)