updated contents from Atlas repo
This commit is contained in:
5
iterables/CACM/citation.txt
Normal file
5
iterables/CACM/citation.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Examples in this directory were adapted from:
|
||||
|
||||
Erik Meijer. 2014. The curse of the excluded middle.
|
||||
Commun. ACM 57, 6 (June 2014), 50-55. DOI=10.1145/2605176
|
||||
http://doi.acm.org/10.1145/2605176
|
||||
10
iterables/CACM/closed_file.py
Normal file
10
iterables/CACM/closed_file.py
Normal file
@@ -0,0 +1,10 @@
|
||||
"""
|
||||
Erik Meijer. 2014. The curse of the excluded middle.
|
||||
Commun. ACM 57, 6 (June 2014), 50-55. DOI=10.1145/2605176
|
||||
http://doi.acm.org/10.1145/2605176
|
||||
"""
|
||||
|
||||
with open('citation.txt', encoding='ascii') as fp:
|
||||
get_contents = lambda: fp.read()
|
||||
|
||||
print(get_contents())
|
||||
17
iterables/CACM/haha.py
Normal file
17
iterables/CACM/haha.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Erik Meijer. 2014. The curse of the excluded middle.
|
||||
Commun. ACM 57, 6 (June 2014), 50-55. DOI=10.1145/2605176
|
||||
http://doi.acm.org/10.1145/2605176
|
||||
"""
|
||||
|
||||
def ha():
|
||||
ha = 'Ha'
|
||||
print(ha)
|
||||
return ha
|
||||
|
||||
# prints 'Ha' twice before showing result
|
||||
print('result ->', ha() + ha())
|
||||
|
||||
# prints 'Ha' only once before showing reult
|
||||
ha_res = ha() # common subexpression elimination
|
||||
print('result ->', ha_res + ha_res)
|
||||
22
iterables/CACM/less_more.py
Normal file
22
iterables/CACM/less_more.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
Meijer, Erik - The Curse of the Excluded Middle
|
||||
DOI:10.1145/2605176
|
||||
CACM vol.57 no.06
|
||||
"""
|
||||
|
||||
def less_than_30(n):
|
||||
check = n < 30
|
||||
print('%d < 30 : %s' % (n, check))
|
||||
return check
|
||||
|
||||
def more_than_20(n):
|
||||
check = n > 20
|
||||
print('%d > 20 : %s' % (n, check))
|
||||
return check
|
||||
|
||||
l = [1, 25, 40, 5, 23]
|
||||
q0 = (n for n in l if less_than_30(n))
|
||||
q1 = (n for n in q0 if more_than_20(n))
|
||||
|
||||
for n in q1:
|
||||
print('-> %d' % n)
|
||||
14
iterables/CACM/zero_div.py
Normal file
14
iterables/CACM/zero_div.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Erik Meijer. 2014. The curse of the excluded middle.
|
||||
Commun. ACM 57, 6 (June 2014), 50-55. DOI=10.1145/2605176
|
||||
http://doi.acm.org/10.1145/2605176
|
||||
"""
|
||||
|
||||
l = range(10, -1, -1)
|
||||
try:
|
||||
res = (1/x for x in l)
|
||||
except ZeroDivisionError:
|
||||
res = []
|
||||
|
||||
for z in res:
|
||||
print(z)
|
||||
Reference in New Issue
Block a user