Skip to content

Commit

Permalink
Merge branch 'russtoku-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Nov 17, 2024
2 parents 71f4f26 + df731b1 commit c562d1b
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 40 deletions.
63 changes: 59 additions & 4 deletions dev/python/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Should be able to evaluate all of these.

def add(a, b):
return a + b

Expand Down Expand Up @@ -49,6 +51,63 @@ def fn_with_multiline_str():

fn_with_multiline_str()

import csv
from datetime import datetime


# Class definition
# - from https://docs.python.org/3/tutorial/classes.html
class Dog:

def __init__(self, name):
self.name = name
self.tricks = []

def add_trick(self, trick):
self.tricks.append(trick)

d = Dog('Fido')
e = Dog('Buddy')
d.add_trick('roll_over')
e.add_trick('play dead')
d.tricks
e.tricks


# Class definition with decorator
# - from https://docs.python.org/3.10/tutorial/classes.html
from dataclasses import dataclass

@dataclass
class Employee:
name: str
dept: str
salary: int

john = Employee('john', 'computer lab', 1000)
john.dept
john.salary


# Function definition with decorator
# - https://docs.python.org/3.8/library/functools.html?highlight=decorator#functools.cached_property
from functools import lru_cache

@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)

[fib(n) for n in range(16)]
# [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]

fib.cache_info()
# CacheInfo(hits=28, misses=16, maxsize=None, currsize=16)


# Asyncio samples
# - Add '-m asyncio' to the python command to evaluate these.

"""
async def slow_fn():
Expand All @@ -68,7 +127,3 @@ async def capture():
await capture()
result
"""


import csv
from datetime import datetime
Empty file modified docs/school
100755 → 100644
Empty file.
22 changes: 15 additions & 7 deletions fnl/conjure/client/python/stdio.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@
; "current form" and not be surprised that it wasn't what you thought.
(fn form-node?
[node]
(or (= "expression_statement" (node:type))
(= "import_statement" (node:type))
(= "import_from_statement" (node:type))
(= "with_statement" (node:type))
(= "function_definition" (node:type))
(= "for_statement" (node:type))
(= "call" (node:type))))
(log.dbg "form-node?: node:type =" (node:type))
(log.dbg "form-node?: node:parent =" (node:parent))
(let [parent (node:parent)]
(if (= "expression_statement" (node:type)) true
(= "import_statement" (node:type)) true
(= "import_from_statement" (node:type)) true
(= "with_statement" (node:type)) true
(= "decorated_definition" (node:type)) true
(= "for_statement" (node:type)) true
(= "call" (node:type)) true
(and (= "class_definition" (node:type))
(not (= "decorated_definition" (parent:type)))) true
(and (= "function_definition" (node:type))
(not (= "decorated_definition" (parent:type)))) true
false)))

(fn with-repl-or-warn [f opts]
(let [repl (state :repl)]
Expand Down
81 changes: 52 additions & 29 deletions lua/conjure/client/python/stdio.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c562d1b

Please sign in to comment.