Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ade9577

Browse filesBrowse files
committed
sync from Atlas
1 parent c93076a commit ade9577
Copy full SHA for ade9577

File tree

Expand file treeCollapse file tree

6 files changed

+21
-28
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+21
-28
lines changed

‎02-array-seq/lispy/py3.10/lis.py

Copy file name to clipboardExpand all lines: 02-array-seq/lispy/py3.10/lis.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def standard_env() -> Environment:
122122
# tag::REPL[]
123123
def repl(prompt: str = 'lis.py> ') -> NoReturn:
124124
"A prompt-read-eval-print loop."
125-
global_env = standard_env()
125+
global_env = Environment({}, standard_env())
126126
while True:
127127
ast = parse(input(prompt))
128128
val = evaluate(ast, global_env)
@@ -200,7 +200,7 @@ def __call__(self, *args: Expression) -> Any: # <3>
200200
################ command-line interface
201201

202202
def run(source: str) -> Any:
203-
global_env = standard_env()
203+
global_env = Environment({}, standard_env())
204204
tokens = tokenize(source)
205205
while tokens:
206206
exp = read_from_tokens(tokens)

‎02-array-seq/lispy/py3.9/lis.py

Copy file name to clipboardExpand all lines: 02-array-seq/lispy/py3.9/lis.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def standard_env() -> Environment:
117117

118118
def repl(prompt: str = 'lis.py> ') -> NoReturn:
119119
"A prompt-read-eval-print loop."
120-
global_env = standard_env()
120+
global_env = Environment({}, standard_env())
121121
while True:
122122
ast = parse(input(prompt))
123123
val = evaluate(ast, global_env)
@@ -190,7 +190,7 @@ def __call__(self, *args: Expression) -> Any:
190190
################ command-line interface
191191

192192
def run(source: str) -> Any:
193-
global_env = standard_env()
193+
global_env = Environment({}, standard_env())
194194
tokens = tokenize(source)
195195
while tokens:
196196
exp = read_from_tokens(tokens)

‎18-with-match/lispy/py3.10/examples_test.py

Copy file name to clipboardExpand all lines: 18-with-match/lispy/py3.10/examples_test.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
# end::EVAL_NUMBER[]
4949
5050
# tag::EVAL_SYMBOL[]
51-
>>> from lis import standard_env
5251
>>> evaluate(parse('+'), standard_env())
5352
<built-in function add>
5453
>>> evaluate(parse('ni!'), standard_env())

‎18-with-match/lispy/py3.10/lis.py

Copy file name to clipboardExpand all lines: 18-with-match/lispy/py3.10/lis.py
+7-14Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def standard_env() -> Environment:
121121
# tag::REPL[]
122122
def repl(prompt: str = 'lis.py> ') -> NoReturn:
123123
"A prompt-read-eval-print loop."
124-
global_env = standard_env()
124+
global_env = Environment({}, standard_env())
125125
while True:
126126
ast = parse(input(prompt))
127127
val = evaluate(ast, global_env)
@@ -140,10 +140,7 @@ def lispstr(exp: object) -> str:
140140
################ Evaluator
141141

142142
# tag::EVALUATE[]
143-
KEYWORDS = {'quote', 'if', 'lambda', 'define', 'set!'}
144-
145-
def is_keyword(s: Any) -> bool:
146-
return isinstance(s, Symbol) and s in KEYWORDS
143+
KEYWORDS = ['quote', 'if', 'lambda', 'define', 'set!']
147144

148145
def evaluate(exp: Expression, env: Environment) -> Any:
149146
"Evaluate an expression in an environment."
@@ -161,17 +158,13 @@ def evaluate(exp: Expression, env: Environment) -> Any:
161158
return evaluate(alternative, env)
162159
case ['lambda', [*parms], *body] if body:
163160
return Procedure(parms, body, env)
164-
case ['define', Symbol(var), value_exp]:
165-
env[var] = evaluate(value_exp, env)
161+
case ['define', Symbol(name), value_exp]:
162+
env[name] = evaluate(value_exp, env)
166163
case ['define', [Symbol(name), *parms], *body] if body:
167164
env[name] = Procedure(parms, body, env)
168-
case ['set!', Symbol(var), value_exp]:
169-
env.change(var, evaluate(value_exp, env))
170-
<<<<<<< HEAD
165+
case ['set!', Symbol(name), value_exp]:
166+
env.change(name, evaluate(value_exp, env))
171167
case [func_exp, *args] if func_exp not in KEYWORDS:
172-
=======
173-
case [func_exp, *args] if not is_keyword(func_exp):
174-
>>>>>>> 3ecfb212c6273122797c76876d6b373b2cb94fa6
175168
proc = evaluate(func_exp, env)
176169
values = [evaluate(arg, env) for arg in args]
177170
return proc(*values)
@@ -202,7 +195,7 @@ def __call__(self, *args: Expression) -> Any: # <3>
202195
################ command-line interface
203196

204197
def run(source: str) -> Any:
205-
global_env = standard_env()
198+
global_env = Environment({}, standard_env())
206199
tokens = tokenize(source)
207200
while tokens:
208201
exp = read_from_tokens(tokens)

‎18-with-match/lispy/py3.9/lis.py

Copy file name to clipboardExpand all lines: 18-with-match/lispy/py3.9/lis.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def standard_env() -> Environment:
117117

118118
def repl(prompt: str = 'lis.py> ') -> NoReturn:
119119
"A prompt-read-eval-print loop."
120-
global_env = standard_env()
120+
global_env = Environment({}, standard_env())
121121
while True:
122122
ast = parse(input(prompt))
123123
val = evaluate(ast, global_env)
@@ -193,7 +193,7 @@ def __call__(self, *args: Expression) -> Any:
193193
################ command-line interface
194194

195195
def run(source: str) -> Any:
196-
global_env = standard_env()
196+
global_env = Environment({}, standard_env())
197197
tokens = tokenize(source)
198198
while tokens:
199199
exp = read_from_tokens(tokens)

‎19-concurrency/primes/spinner_prime_async_nap.py

Copy file name to clipboardExpand all lines: 19-concurrency/primes/spinner_prime_async_nap.py
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import asyncio
88
import itertools
99
import math
10+
import functools
1011

1112
# tag::PRIME_NAP[]
1213
async def is_prime(n):
@@ -21,8 +22,8 @@ async def is_prime(n):
2122
for i in range(3, root + 1, 2):
2223
if n % i == 0:
2324
return False
24-
if i % 100_000 == 1: # <2>
25-
await asyncio.sleep(0)
25+
if i % 100_000 == 1:
26+
await asyncio.sleep(0) # <1>
2627
return True
2728
# end::PRIME_NAP[]
2829

@@ -39,13 +40,13 @@ async def spin(msg: str) -> None:
3940
print(f'\r{blanks}\r', end='')
4041

4142
async def check(n: int) -> int:
42-
return await is_prime(n) # <4>
43+
return await is_prime(n)
4344

4445
async def supervisor(n: int) -> int:
45-
spinner = asyncio.create_task(spin('thinking!')) # <1>
46-
print('spinner object:', spinner) # <2>
47-
result = await check(n) # <3>
48-
spinner.cancel() # <5>
46+
spinner = asyncio.create_task(spin('thinking!'))
47+
print('spinner object:', spinner)
48+
result = await check(n)
49+
spinner.cancel()
4950
return result
5051

5152
def main() -> None:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.