一键导入
dispatch-on-structure
For heterogeneous data: pattern matching on type/structure, interpreter eval loops, handling different expression types.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
For heterogeneous data: pattern matching on type/structure, interpreter eval loops, handling different expression types.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
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 | dispatch-on-structure |
| description | For heterogeneous data: pattern matching on type/structure, interpreter eval loops, handling different expression types. |
Check structure/type of input and dispatch to appropriate handler.
def process(x):
"""Dispatch based on structure of x."""
if isinstance(x, int):
return handle_int(x)
if isinstance(x, list) and len(x) == 0:
return handle_empty()
if isinstance(x, list) and x[0] == 'quote':
return handle_quote(x[1])
if isinstance(x, list):
return handle_list(x)
raise TypeError(f"Unknown type: {type(x)}")
def eval(x, env=global_env):
"""Evaluate an expression in an environment."""
# Dispatch on structure of x
if isinstance(x, Symbol): # Variable reference
return env[x]
elif not isinstance(x, List): # Constant literal
return x
elif x[0] == 'quote': # (quote exp)
(_, exp) = x
return exp
elif x[0] == 'if': # (if test conseq alt)
(_, test, conseq, alt) = x
exp = conseq if eval(test, env) else alt
return eval(exp, env)
elif x[0] == 'define': # (define var exp)
(_, var, exp) = x
env[var] = eval(exp, env)
elif x[0] == 'lambda': # (lambda (var...) body)
(_, parms, body) = x
return Procedure(parms, body, env)
else: # (proc arg...)
proc = eval(x[0], env)
args = [eval(exp, env) for exp in x[1:]]
return proc(*args)
# Differentiation dispatch (Differentiation.ipynb)
def D(y, x):
"""Differentiate y with respect to x."""
if y == x:
return 1
if not isinstance(y, Expression):
return 0
if len(y.args) == 1: # Unary: sin, cos, etc.
return D_unary(y, x)
if len(y.args) == 2: # Binary: +, *, etc.
return D_binary(y, x)
raise ValueError(f"Unknown arity: {y}")
(_, test, conseq, alt) = xx[0] == 'quote' for tagged lists