一键导入
intern-symbols-identity
For fast comparison: ensure only one instance of each symbol, use 'is' instead of '==', symbol tables for interpreters.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
For fast comparison: ensure only one instance of each symbol, use 'is' instead of '==', symbol tables for interpreters.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | intern-symbols-identity |
| description | For fast comparison: ensure only one instance of each symbol, use 'is' instead of '==', symbol tables for interpreters. |
is vs ==)Use a table to ensure each unique symbol exists only once.
class Symbol(str):
"""A symbol is a unique string."""
pass
def Sym(s, symbol_table={}):
"""Return the unique Symbol for string s."""
if s not in symbol_table:
symbol_table[s] = Symbol(s)
return symbol_table[s]
# Now identity comparison works
quote = Sym('quote')
assert Sym('quote') is quote # Same object!
assert Sym('quote') is Sym('quote') # Always same object
# Fast dispatch with 'is'
if x[0] is quote: # Faster than x[0] == 'quote'
return handle_quote(x)
class Symbol(str):
"""A Lisp Symbol is implemented as a Python str subclass."""
pass
def Sym(s, symbol_table={}):
"""Find or create unique Symbol entry for str s in symbol table."""
if s not in symbol_table:
symbol_table[s] = Symbol(s)
return symbol_table[s]
# Pre-intern common symbols
_quote, _if, _set, _define, _lambda, _begin, _definemacro = map(Sym,
"quote if set! define lambda begin define-macro".split())
_quasiquote, _unquote, _unquotesplicing = map(Sym,
"quasiquote unquote unquote-splicing".split())
# Fast dispatch in eval using 'is'
def eval(x, env=global_env):
if isinstance(x, Symbol):
return env.find(x)[x]
elif not isinstance(x, list):
return x
elif x[0] is _quote: # Fast identity check
return x[1]
elif x[0] is _if: # Fast identity check
(_, test, conseq, alt) = x
return eval(conseq if eval(test, env) else alt, env)
elif x[0] is _define: # Fast identity check
(_, var, exp) = x
env[var] = eval(exp, env)
# ... more special forms
# Note: Using 'is' instead of '==' because symbols are interned
symbol_table={} persistsis for dispatch: Faster than string comparisonSym()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.