Skip to content

Commit c562d1b

Browse files
committed
Merge branch 'russtoku-main'
2 parents 71f4f26 + df731b1 commit c562d1b

File tree

4 files changed

+126
-40
lines changed

4 files changed

+126
-40
lines changed

dev/python/sandbox.py

+59-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Should be able to evaluate all of these.
2+
13
def add(a, b):
24
return a + b
35

@@ -49,6 +51,63 @@ def fn_with_multiline_str():
4951

5052
fn_with_multiline_str()
5153

54+
import csv
55+
from datetime import datetime
56+
57+
58+
# Class definition
59+
# - from https://docs.python.org/3/tutorial/classes.html
60+
class Dog:
61+
62+
def __init__(self, name):
63+
self.name = name
64+
self.tricks = []
65+
66+
def add_trick(self, trick):
67+
self.tricks.append(trick)
68+
69+
d = Dog('Fido')
70+
e = Dog('Buddy')
71+
d.add_trick('roll_over')
72+
e.add_trick('play dead')
73+
d.tricks
74+
e.tricks
75+
76+
77+
# Class definition with decorator
78+
# - from https://docs.python.org/3.10/tutorial/classes.html
79+
from dataclasses import dataclass
80+
81+
@dataclass
82+
class Employee:
83+
name: str
84+
dept: str
85+
salary: int
86+
87+
john = Employee('john', 'computer lab', 1000)
88+
john.dept
89+
john.salary
90+
91+
92+
# Function definition with decorator
93+
# - https://docs.python.org/3.8/library/functools.html?highlight=decorator#functools.cached_property
94+
from functools import lru_cache
95+
96+
@lru_cache(maxsize=None)
97+
def fib(n):
98+
if n < 2:
99+
return n
100+
return fib(n-1) + fib(n-2)
101+
102+
[fib(n) for n in range(16)]
103+
# [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]
104+
105+
fib.cache_info()
106+
# CacheInfo(hits=28, misses=16, maxsize=None, currsize=16)
107+
108+
109+
# Asyncio samples
110+
# - Add '-m asyncio' to the python command to evaluate these.
52111

53112
"""
54113
async def slow_fn():
@@ -68,7 +127,3 @@ async def capture():
68127
await capture()
69128
result
70129
"""
71-
72-
73-
import csv
74-
from datetime import datetime

docs/school

100755100644
File mode changed.

fnl/conjure/client/python/stdio.fnl

+15-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@
3838
; "current form" and not be surprised that it wasn't what you thought.
3939
(fn form-node?
4040
[node]
41-
(or (= "expression_statement" (node:type))
42-
(= "import_statement" (node:type))
43-
(= "import_from_statement" (node:type))
44-
(= "with_statement" (node:type))
45-
(= "function_definition" (node:type))
46-
(= "for_statement" (node:type))
47-
(= "call" (node:type))))
41+
(log.dbg "form-node?: node:type =" (node:type))
42+
(log.dbg "form-node?: node:parent =" (node:parent))
43+
(let [parent (node:parent)]
44+
(if (= "expression_statement" (node:type)) true
45+
(= "import_statement" (node:type)) true
46+
(= "import_from_statement" (node:type)) true
47+
(= "with_statement" (node:type)) true
48+
(= "decorated_definition" (node:type)) true
49+
(= "for_statement" (node:type)) true
50+
(= "call" (node:type)) true
51+
(and (= "class_definition" (node:type))
52+
(not (= "decorated_definition" (parent:type)))) true
53+
(and (= "function_definition" (node:type))
54+
(not (= "decorated_definition" (parent:type)))) true
55+
false)))
4856

4957
(fn with-repl-or-warn [f opts]
5058
(let [repl (state :repl)]

lua/conjure/client/python/stdio.lua

+52-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)