with one click
cascade-type-conversion
// For flexible parsing: try multiple type conversions in order, graceful fallback from specific to general types.
// For flexible parsing: try multiple type conversions in order, graceful fallback from specific to general types.
Conducts iterative deep research on any topic using web search, progressive exploration, and structured synthesis. Use when asked for comprehensive research, deep investigation, thorough analysis, or multi-source exploration of any topic. Triggers: research, investigate, deep dive, comprehensive analysis, explore thoroughly, find everything about.
For cross-cutting concerns: add behavior without modifying functions, caching, timing, logging, validation wrappers.
For performance work: measure before changing, profile to find bottlenecks, compare before and after.
For symbolic computation: ASTs, mathematical expressions, code that manipulates code structure, expression transformations.
For ordered processing: A* search, Dijkstra, event simulation, task scheduling. Efficient min/max extraction with heap-based queue.
For dynamic programming: overlapping subproblems, recursive solutions with repeated computations, memoization to avoid redundant work.
| name | cascade-type-conversion |
| description | For flexible parsing: try multiple type conversions in order, graceful fallback from specific to general types. |
Try conversions from most specific to most general, catching failures.
def parse_value(s):
"""Parse string as most specific type possible."""
# Try int first
try:
return int(s)
except ValueError:
pass
# Try float
try:
return float(s)
except ValueError:
pass
# Try bool
if s.lower() in ('true', 'false'):
return s.lower() == 'true'
# Fall back to string
return s
# Lisp atom parsing (lispy.py)
def atom(token):
"""Numbers become numbers; #t/#f are booleans; strings stay strings."""
if token == '#t':
return True
elif token == '#f':
return False
elif token[0] == '"':
return token[1:-1] # Strip quotes
try:
return int(token)
except ValueError:
try:
return float(token)
except ValueError:
try:
return complex(token.replace('i', 'j', 1))
except ValueError:
return Sym(token)
# Simpler version (lis.py)
def atom(token):
"""Numbers become numbers; every other token is a symbol."""
try:
return int(token)
except ValueError:
try:
return float(token)
except ValueError:
return Symbol(token)
# Advent of Code parsing (AdventUtils.ipynb)
def atom(text: str):
"""Parse text into a single float or int or str."""
try:
x = float(text)
return round(x) if x.is_integer() else x
except ValueError:
return text.strip()
# Version compatibility (beal.py)
try:
from math import gcd # Python 3.6+
except ImportError:
from fractions import gcd # Older Python