In this section, all optional arguments called @var{port} default to
the current input port.
-@deffn {standard procedure} read [port [environment]]
+@deffn {standard procedure} read [port]
@cindex expression, input from port
@cindex external representation, parsing
@cindex parsing, of external representation
the beginning of an object's written representation, but the written
representation is incomplete and therefore not parsable, an error is
signalled.
-
-The optional argument @var{environment} is an MIT/GNU Scheme extension
-that is used to look up the values of control variables such as
-@code{param:reader-radix} (@pxref{reader-controls}). If not supplied,
-it defaults to the @acronym{REP} environment.
@end deffn
@deffn {standard procedure} read-char [port]
@subsection Reader Controls
The following parameters control the behavior of the @code{read}
-procedure. They are looked up in the environment that is passed to
-@code{read}, and so may have different values in different
-environments. The global parameters may be dynamically bound by
-@code{parameterize}, but should not be mutated. Make persistent,
-local changes by shadowing the global bindings in the local
-environment and assigning new parameters to them.
+procedure.
@deffn parameter param:reader-radix
This parameter defines the radix used by the reader when it parses
@code{(interaction-i/o-port)}; this is initially the console
@acronym{I/O} port.
-@deffn procedure prompt-for-command-expression prompt [port [environment]]
+@deffn procedure prompt-for-command-expression prompt [port]
Prompts the user for an expression that is to be executed as a command.
This is the procedure called by the @acronym{REP} loop to read the
user's expressions.
and a space. Also, a space is appended to the string, unless it already
ends in a space or is an empty string.
-If @var{environment} is given, it is passed as the second argument to
-@code{read}.
-
The default behavior of this procedure is to print a fresh line, a
newline, and the prompt string; flush the output buffer; then read an
object and return it.
returned as the value of this procedure.
@end deffn
-@deffn procedure prompt-for-expression prompt [port [environment]]
+@deffn procedure prompt-for-expression prompt [port]
Prompts the user for an expression.
The prompt string is formed by appending a colon and a space to
@var{prompt}, unless @var{prompt} already ends in a space or is the null
string.
-If @var{environment} is given, it is passed as the second argument to
-@code{read}.
-
The default behavior of this procedure is to print a fresh line, a
newline, and the prompt string; flush the output buffer; then read an
object and return it.
(newline port)
(newline port))
-(define (operation/prompt-for-expression port environment prompt)
- port environment
+(define (operation/prompt-for-expression port prompt)
+ port
(prompt-for-expression prompt))
(define (operation/prompt-for-confirmation port prompt)
(define interface-port-type
(make-port-type
- `((WRITE-CHAR
+ `((write-char
,(lambda (port char)
(guarantee 8-bit-char? char)
(region-insert-char! (port/state port) char)
1))
- (PROMPT-FOR-CONFIRMATION
- ,(lambda (port prompt) port (prompt-for-confirmation? prompt)))
- (PROMPT-FOR-EXPRESSION
- ,(lambda (port environment prompt)
- port environment
+ (prompt-for-confirmation
+ ,(lambda (port prompt)
+ (declare (ignore port))
+ (prompt-for-confirmation? prompt)))
+ (prompt-for-expression
+ ,(lambda (port prompt)
+ (declare (ignore port))
(prompt-for-expression prompt))))
#f))
;; This sets up the correct environment in the typein buffer
;; so that completion of variables works right.
(local-set-variable! scheme-environment environment buffer))
- options)
- environment)))
+ options))))
-(define (read-from-string string environment)
+(define (read-from-string string)
(bind-condition-handler (list condition-type:error) evaluation-error-handler
(lambda ()
- (read (open-input-string string) environment))))
+ (read (open-input-string string)))))
(define-major-mode prompt-for-expression scheme #f
(mode-description (ref-mode-object minibuffer-local))
evaluation-error-handler
(lambda ()
(let loop
- ((expressions (read-expressions-from-region region environment))
+ ((expressions (read-expressions-from-region region))
(result unspecific))
(if (null? expressions)
result
(loop (cdr expressions)
(editor-eval buffer (car expressions) environment))))))))
-(define (read-expressions-from-region region #!optional environment)
- (let ((environment
- (if (default-object? environment)
- (evaluation-environment region)
- environment)))
- (call-with-input-region region
- (lambda (port)
- (let loop ()
- (let ((expression (read port environment)))
- (if (eof-object? expression)
- '()
- (cons expression (loop)))))))))
+(define (read-expressions-from-region region)
+ (call-with-input-region region
+ (lambda (port)
+ (let loop ()
+ (let ((expression (read port)))
+ (if (eof-object? expression)
+ '()
+ (cons expression (loop))))))))
(define (evaluation-environment #!optional buffer global-ok?)
(let ((buffer (->buffer buffer)))
\f
;;; Prompting
-(define (operation/prompt-for-expression port environment prompt)
- (unsolicited-prompt port
- (lambda (prompt)
- (prompt-for-expression prompt #!default environment))
- prompt))
+(define (operation/prompt-for-expression port prompt)
+ (unsolicited-prompt port prompt-for-expression prompt))
(define (operation/prompt-for-confirmation port prompt)
(unsolicited-prompt port prompt-for-confirmation? prompt))
(remove-select-buffer-hook buffer hook))))))
(add-select-buffer-hook buffer hook))))
-(define (operation/prompt-for-command-expression port environment prompt level)
- environment
+(define (operation/prompt-for-command-expression port prompt level)
(parse-command-prompt port prompt)
(read-expression port level))
(prompt-for-string "Redo" #f
'DEFAULT-TYPE 'INSERTED-DEFAULT
'HISTORY 'REPEAT-COMPLEX-COMMAND
- 'HISTORY-INDEX (- argument 1))
- (->environment '(EDWIN))))))
+ 'HISTORY-INDEX (- argument 1))))))
\f
;;;; Pass-phrase Prompts
(run-in-nearest-repl
(lambda (repl)
(let ((environment (repl/environment repl)))
- (repl-eval/write (read (open-input-string arg)
- environment)
+ (repl-eval/write (read (open-input-string arg))
environment
repl)))))
"Evaluates the argument expressions as if in the REPL.")
(define (debug/read-eval-print-1 environment port)
(let ((value
- (debug/eval (prompt-for-expression "Evaluate expression"
- port environment)
+ (debug/eval (prompt-for-expression "Evaluate expression" port)
environment)))
(if (undefined-value? value)
(debugger-message port "No value")
(if invalid-expression?
""
" ($ to retry)"))
- port
- environment)))
+ port)))
(if (and (not invalid-expression?)
(eq? expression '$))
(debug/scode-eval (dstate/expression dstate)
\f
;;;; Prompting
-(define (emacs/prompt-for-command-expression port environment prompt level)
+(define (emacs/prompt-for-command-expression port prompt level)
(transmit-modeline-string port prompt level)
(transmit-signal port #\R)
- (read port environment))
+ (read port))
(define (emacs/prompt-for-command-char port prompt level)
(transmit-modeline-string port prompt level)
'(("debug> " "[Debug]")
("where> " "[Where]")))
-(define (emacs/prompt-for-expression port environment prompt)
+(define (emacs/prompt-for-expression port prompt)
(transmit-signal-with-argument port #\i prompt)
- (read port environment))
+ (read port))
(define (emacs/prompt-for-confirmation port prompt)
(transmit-signal-with-argument
(else (eof-object)))))
"")))
\f
-(define (read #!optional port environment)
- (declare (ignore environment))
+(define (read #!optional port)
(read-top-level (optional-input-port port 'read)))
-(define (read-file pathname #!optional environment)
- (declare (ignore environment))
+(define (read-file pathname)
(call-with-input-file (pathname-default-version pathname 'newest)
(lambda (port)
(let loop ((sexps '()))
(call-with-input-file pathname
(lambda (port)
(let loop ((value unspecific))
- (let ((sexp (read port environment)))
+ (let ((sexp (read port)))
(if (eof-object? sexp)
value
(loop (repl-eval sexp environment)))))))))
(do () (#f)
(if (queue-empty? queue)
(let ((environment (repl/environment repl)))
- (%repl-eval/write (hook/repl-read environment repl)
+ (%repl-eval/write (hook/repl-read repl)
environment
repl))
((dequeue! queue) repl)))))
(guarantee unary-procedure? procedure 'run-in-nearest-repl)
(enqueue! (repl/input-queue (nearest-repl)) procedure))
\f
-(define (repl-read #!optional environment repl)
- (receive (environment repl) (optional-er environment repl 'repl-read)
- (hook/repl-read environment repl)))
+(define (repl-read #!optional repl)
+ (hook/repl-read
+ (if (default-object? repl)
+ (nearest-repl)
+ (guarantee repl? repl 'repl-read))))
(define hook/repl-read)
-(define (default/repl-read environment repl)
+(define (default/repl-read repl)
(prompt-for-command-expression (cons 'standard (repl/prompt repl))
- (cmdl/port repl)
- environment))
+ (cmdl/port repl)))
(define (repl-eval s-expression #!optional environment repl)
(receive (environment repl) (optional-er environment repl 'repl-eval)
(let ((repl
(if (default-object? repl)
(nearest-repl)
- (begin
- (guarantee repl? repl caller)
- repl))))
+ (guarantee repl? repl caller))))
(values (if (default-object? environment)
(repl/environment repl)
(guarantee environment? environment caller))
\f
;;;; Prompting
-(define (prompt-for-command-expression prompt #!optional port environment)
+(define (prompt-for-command-expression prompt #!optional port)
(let ((prompt (canonicalize-command-prompt prompt))
(port (optional-port port 'prompt-for-command-expression))
- (environment
- (optional-environment environment 'prompt-for-command-expression))
(level (nearest-cmdl/level)))
(let ((operation
(textual-port-operation port 'prompt-for-command-expression)))
(if operation
- (operation port environment prompt level)
+ (operation port prompt level)
(begin
(guarantee textual-i/o-port? port 'prompt-for-command-expression)
(write-command-prompt port prompt level)
(with-input-port-terminal-mode port 'cooked
(lambda ()
- (read port environment))))))))
+ (read port))))))))
-(define (prompt-for-expression prompt #!optional port environment)
- (%prompt-for-expression
- (optional-port port 'prompt-for-expression)
- (optional-environment environment 'prompt-for-expression)
- prompt
- 'prompt-for-expression))
+(define (prompt-for-expression prompt #!optional port)
+ (%prompt-for-expression port prompt 'prompt-for-expression))
(define (prompt-for-evaluated-expression prompt #!optional environment port)
- (let ((environment
- (optional-environment environment 'prompt-for-evaluated-expression))
- (port (optional-port port 'prompt-for-evaluated-expression)))
- (repl-eval
- (%prompt-for-expression port
- environment
- prompt
- 'prompt-for-evaluated-expression)
- environment)))
-
-(define (%prompt-for-expression port environment prompt caller)
- (let ((prompt (canonicalize-prompt prompt ": ")))
+ (repl-eval
+ (%prompt-for-expression port prompt 'prompt-for-evaluated-expression)
+ (if (default-object? environment)
+ (nearest-repl/environment)
+ (guarantee environment? environment 'prompt-for-evaluated-expression))))
+
+(define (%prompt-for-expression port prompt caller)
+ (let ((port (optional-port port caller))
+ (prompt (canonicalize-prompt prompt ": ")))
(let ((operation (textual-port-operation port 'prompt-for-expression)))
(if operation
- (operation port environment prompt)
+ (operation port prompt)
(begin
(guarantee textual-i/o-port? port caller)
(with-output-port-terminal-mode port 'cooked
(flush-output-port port)))
(with-input-port-terminal-mode port 'cooked
(lambda ()
- (read port environment))))))))
+ (read port))))))))
(define (optional-port port caller)
(if (default-object? port)
(interaction-i/o-port)
(guarantee textual-port? port caller)))
-
-(define (optional-environment environment caller)
- (if (default-object? environment)
- (nearest-repl/environment)
- (guarantee environment? environment caller)))
\f
(define (prompt-for-command-char prompt #!optional port)
(let ((prompt (canonicalize-command-prompt prompt))
(show-environment-procedure (car (wstate/frame-list wstate)) port))
(define (recursive-where wstate port)
- (let ((environment (car (wstate/frame-list wstate))))
- (let ((inp
- (prompt-for-expression "Object to evaluate and examine"
- port
- environment)))
- (debugger-message port "New where!")
- (debug/where (debug/eval inp environment)))))
+ (let ((inp (prompt-for-expression "Object to evaluate and examine" port)))
+ (debugger-message port "New where!")
+ (debug/where (debug/eval inp (car (wstate/frame-list wstate))))))
(define (enter wstate port)
port