Add files via upload
This commit is contained in:
parent
5d0223c63e
commit
6c51ac830d
@ -37,7 +37,7 @@
|
||||
"\n",
|
||||
"# The Concordance Solution\n",
|
||||
"\n",
|
||||
"I ended up with a program similar to the following, but to avoid having to explain Snobol, here I show Python syntax (except for the `'$word'` indirection):"
|
||||
"I ended up with a program similar to the following (translated from Snobol to Python augmented with `'$word'` indirection):"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -51,7 +51,7 @@
|
||||
"program = \"\"\"\n",
|
||||
"for i, line in enumerate(input):\n",
|
||||
" for word in re.findall(r\"\\w+\", line.upper()):\n",
|
||||
" $word += str(i) + \", \"\n",
|
||||
" $word += str(i) + ', '\n",
|
||||
"\"\"\""
|
||||
]
|
||||
},
|
||||
@ -61,7 +61,7 @@
|
||||
"source": [
|
||||
"That's just 3 lines, not 40 to 60! \n",
|
||||
"\n",
|
||||
"To test the program, I'll write a mock Snobol/Python interpreter, which at heart is just a call to the Python interpreter, `exec(program)`, except that it handles the three things I noticed about Snobol:\n",
|
||||
"To test the program, I'll write a mock Snobol/Python interpreter, which at heart is just a call to the Python interpreter, `exec(program)`, except that it handles the three things I noticed about the Snobol interpreter:\n",
|
||||
"\n",
|
||||
"* `$word` gets translated as `_context[word]`.\n",
|
||||
"* It calls `exec(program, _context)`, where `_context` is a `defaultdict(str)`, so variables default to `''`.\n",
|
||||
@ -224,7 +224,7 @@
|
||||
"program = \"\"\"\n",
|
||||
"for i, line in enumerate(input):\n",
|
||||
" for word in re.findall(r\"\\w+\", line.upper()):\n",
|
||||
" $word += str(i) + \", \"\n",
|
||||
" $word += str(i) + ', '\n",
|
||||
"del i, line, word\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
|
Loading…
Reference in New Issue
Block a user