While interactively executing the following code in http://pythontutor.com/visualize.html, the frame of each call to build_match_and_apply_functions
appears gray in the graphical view:
This program is for getting a plural of a word , which is quoted from the chapter in DIVE in Python 3
CODE:
import re
def build_match_and_apply_functions(pattern, search, replace):
def matches_rule(word):
return re.search(pattern, word)
def apply_rule(word):
return re.sub(search, replace, word)
return (matches_rule, apply_rule)
patterns = \
(
('[sxz]$', '$', 'es'),
('[^aeioudgkprt]h$', '$', 'es'),
('(qu|[^aeiou])y$', 'y$', 'ies'),
('$', '$', 's')
)
rules = [build_match_and_apply_functions(pattern, search, replace)
for (pattern, search, replace) in patterns]
def plural(noun):
for matches_rule, apply_rule in rules:
if matches_rule(noun):
return apply_rule(noun)
plural('vacancy')
question:
1) what does gray frame mean? it is a closure that still takes memory?
2) can I go in memory block. so i can figure out in the objects area , are all matches_rule functions the same or not? if they are the same , f2/f3/f4/f5 should be there to offer pattern/search/replace values.
if not, if all matches_rules functions have already be changed to different functions , f2 3 4 5 could be end of live and dispear. they are useless.
i dont know , that is how dynamic language works and being built.
pythontutor.com ANALYZE DIGRAM really surprised me, tutor did the good job
if u dont expirence it, please copy the link below and paste my code in it. i bet you are having fun with it.