David Lichteblau <david@...> writes:
> Quoting Christophe Rhodes (csr21@...):
>> Shouldn't the bindings you introduced in SB-ACLREPL actually be done
>> outside the thing that calls *REPL-FUN*? Handwavily: instead of
> Yes, and that probably is the right solution for the *PACKAGE* problem.
> Unfortunately, sb-aclrepl has other state, at least *dir-stack*,
> *history*, and *cmd-number*, all internal symbols in the sb-aclrepl
> package. In src/code/toplevel.lisp, those symbols cannot be bound since
> they do not exist (yet).
Ah yes, I see. Nasty.
>> Surely REPL functions are about reading, evaling and printing, and
>> what calls them is what is responsible for them having a sane
>> state... am I missing something?
> So let me propose yet another solution. Replace *REPL-FUN* with
> *REPL-CLASS*, a class name. TOPLEVEL-REPL in code/toplevel.lisp
> instantiates this class, and binds a single (!) special variable *REPL*
> to the new instance. ACLREPL, a subclass of the standard REPL, keeps
> its state as slots in that instance. E.g., *dir-stack*, *history*, and
> *cmd-number* all go away. Voila -- we can establish a sane state
> without having to know REPL-specific symbols.
This precise solution might not fly -- when we first need a REPL, at
the beginning of warm load, we don't yet have CLOS. :-/ This is
workaroundable, but it wouldn't be pretty.
On the other hand, we could fake objects with closures, in the best
Scheme tradition :-)
WARNING: UGLINESS APPROACHING!
(defun make-repl-fun ()
(let ((dir-stack nil)
(lambda (&key break-level ...)
(let ((*dir-stack* dir-stack)
... body of sb-aclrepl ...
(setf dir-stack *dir-stack*
;;; is this *REPL-FUN* bound? This SETF would have to be on a
;;; per-thread special, so that separate threads have their own
(setf sb-impl::*repl-fun* (make-repl-fun))
END OF UGLINESS
I think this has the desired properties: separate bindings of
*REPL-FUN* have separate states, and non-local exits from the REPL
store the current state such that it's restored on re-entry... does
http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge)