Skip to content

Commit b41111c

Browse files
dsblankclaude
andcommitted
Fix procedure repr regression: restore #<procedure> display
PR #43's perf optimization switched procedures from cons-list to raw Python tuples, but nothing gave the tuple a custom repr, so notebook Out[] cells and Python repr() dumped the raw (tag, fn, bodies, formals, env, safe) contents instead of "#<procedure>". make_proc now wraps its result in _ProcTuple, a zero-overhead tuple subclass with __repr__, leaving the hotter continuation/fail/handler construction paths untouched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 6ae3c3a commit b41111c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

calysto_scheme/scheme.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,16 @@ def vector_length(vec):
545545
### literals instead of these names -- see the comment on _eval_direct
546546
### about extra-overhead-per-node being measurable on those paths.
547547

548+
class _ProcTuple(tuple):
549+
# A plain tuple subclass so procedures still repr as "#<procedure>"
550+
# (matching the old cons-based representation) instead of dumping
551+
# their raw (fn, bodies, formals, env, safe) contents.
552+
__slots__ = ()
553+
def __repr__(self):
554+
return "#<procedure>"
555+
548556
def make_proc(*args):
549-
return (symbol_procedure,) + args
557+
return _ProcTuple((symbol_procedure,) + args)
550558

551559
def make_macro(*args):
552560
return (symbol_macro_transformer,) + args

calysto_scheme/src/Scheme.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,16 @@ def vector_length(vec):
537537
### literals instead of these names -- see the comment on _eval_direct
538538
### about extra-overhead-per-node being measurable on those paths.
539539

540+
class _ProcTuple(tuple):
541+
# A plain tuple subclass so procedures still repr as "#<procedure>"
542+
# (matching the old cons-based representation) instead of dumping
543+
# their raw (fn, bodies, formals, env, safe) contents.
544+
__slots__ = ()
545+
def __repr__(self):
546+
return "#<procedure>"
547+
540548
def make_proc(*args):
541-
return (symbol_procedure,) + args
549+
return _ProcTuple((symbol_procedure,) + args)
542550

543551
def make_macro(*args):
544552
return (symbol_macro_transformer,) + args

0 commit comments

Comments
 (0)