File tree Expand file tree Collapse file tree 2 files changed +4
-28
lines changed
Expand file tree Collapse file tree 2 files changed +4
-28
lines changed Original file line number Diff line number Diff line change @@ -227,18 +227,10 @@ def see(x):
227227 # one-liner
228228 f2 = lambda lst : (lambda seen : [seen .add (x ) or x for x in lst if x not in seen ])(seen = set ())
229229
230- # context manager only
231- def f3 (lst ):
232- with _env (seen = set ()) as myenv :
233- return [myenv .seen .add (x ) or x for x in lst if x not in myenv .seen ]
234- # myenv still lives due to Python's scoping rules.
235- # This is why we provide a separate let construct
236- # and not just the env class.
237-
238- f4 = lambda lst : let (seen = set (),
230+ f3 = lambda lst : let (seen = set (),
239231 body = lambda e : [e .seen .add (x ) or x for x in lst if x not in e .seen ])
240232
241- f5 = lambda lst : letrec (seen = lambda e : set (),
233+ f4 = lambda lst : letrec (seen = lambda e : set (),
242234 see = lambda e : lambda x : begin (e .seen .add (x ), x ),
243235 body = lambda e : [e .see (x ) for x in lst if x not in e .seen ])
244236
@@ -250,9 +242,8 @@ def f3(lst):
250242 assert f2 (L ) == f2 (L )
251243 assert f3 (L ) == f3 (L )
252244 assert f4 (L ) == f4 (L )
253- assert f5 (L ) == f5 (L )
254245
255- assert f (L ) == f2 (L ) == f3 (L ) == f4 (L ) == f5 ( L ) == [1 , 3 , 2 , 4 ]
246+ assert f (L ) == f2 (L ) == f3 (L ) == f4 (L ) == [1 , 3 , 2 , 4 ]
256247
257248 uniqify_test ()
258249
Original file line number Diff line number Diff line change 33"""Environment for let constructs."""
44
55class env :
6- """Bunch with context manager, iterator and subscripting support.
6+ """Bunch with iterator and subscripting support.
77
88 Iteration and subscripting just expose the underlying dict.
99
1010 Also works as a bare bunch.
1111
1212 Usage:
13- # with context manager:
14- with env(x = 0) as myenv:
15- print(myenv.x)
16- # DANGER: myenv still exists due to Python's scoping rules.
17-
1813 # bare bunch:
1914 myenv2 = env(s="hello", orange="fruit", answer=42)
2015 print(myenv2.s)
@@ -45,16 +40,6 @@ def __getattr__(self, name):
4540 else :
4641 raise AttributeError ("Name '{:s}' not in environment" .format (name ))
4742
48- # context manager
49- #
50- def __enter__ (self ):
51- return self
52-
53- def __exit__ (self , et , ev , tb ):
54- # we could nuke our *contents* to make all names in the environment
55- # disappear, but it's simpler and more predictable not to.
56- pass
57-
5843 # iteration
5944 #
6045 def __iter__ (self ):
You can’t perform that action at this time.
0 commit comments