Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.lisp > #61736 > unrolled thread

REPL, streams, SBCL

Started bysteve g <Sgonedes1977@gmail.com>
First post2026-10-12 17:32 -0400
Last post2026-10-15 15:06 -0400
Articles 3 — 2 participants

Back to article view | Back to comp.lang.lisp


Contents

  REPL, streams, SBCL steve g <Sgonedes1977@gmail.com> - 2026-10-12 17:32 -0400
    Re: REPL, streams, SBCL Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-10-12 23:23 +0000
      Re: REPL, streams, SBCL steve g <Sgonedes1977@gmail.com> - 2026-10-15 15:06 -0400

#61736 — REPL, streams, SBCL

Fromsteve g <Sgonedes1977@gmail.com>
Date2026-10-12 17:32 -0400
SubjectREPL, streams, SBCL
Message-ID<87wlrmeha9.fsf@gmail.com>
I was interested in changing the REPL for SBCL. I cannot figure out
sb-aclrepl.

I have tried closing *standard-output* and *standard-input*; that
doesn't word very well.

I have been doing this:

(defstruct (screen (:copier nil))
    "The main screen for the program."
   (namestring  "Standard Screen" :type string :read-only t)
   ;; io
   (input        (make-instance 'sb-sys:fd-stream ) :type SB-SYS:FD-STREAM)
   (output       (make-instance 'sb-sys:fd-stream ) :type SB-SYS:FD-STREAM)
   (ofd          0 :type sb-posix:file-descriptor)
   (ifd          0 :type sb-posix:file-descriptor)
   ;; [ ... ]
   )



(DEFUN TIDEVICE-OPEN (TTY)
  (LET ((CURDEV (CURRENT-TIDEVICE)))
    (IF (NULL TTY)
        (SETQ TTY "/dev/pts/1"))
    (SETQ TTY (NAMESTRING TTY))
    (LET* ((OFD
            (SB-POSIX:OPEN TTY SB-POSIX:O-WRONLY
                           (LOGIOR SB-POSIX:O-NOCTTY SB-POSIX:O-NONBLOCK SB-POSIX:O-DIRECT SB-POSIX:O-NDELAY)))
           (IFD (SB-POSIX:OPEN TTY SB-POSIX:O-RDONLY SB-POSIX:O-NOCTTY))
           (OUTPUT
            (SB-SYS:MAKE-FD-STREAM OFD :NAME "Device Output" :AUTO-CLOSE T :OUTPUT T :INPUT NIL :BUFFERING :NONE
                                   :ELEMENT-TYPE 'CHARACTER :EXTERNAL-FORMAT :ASCII))
           (INPUT
            (SB-SYS:MAKE-FD-STREAM IFD :NAME "Device Input" :AUTO-CLOSE T :BUFFERING :NONE :OUTPUT NIL :INPUT T
                                   :ELEMENT-TYPE '(UNSIGNED-BYTE 8) :TIMEOUT 127/400))
           (SB-POSIX:TCGETATTR IFD (TIDEVICE-TERMIOS-OLD CURDEV))
           (SB-POSIX:TCGETATTR IFD (TIDEVICE-TERMIOS-NEW CURDEV)))))
    [ ... ]
    )


;; these are fd-streams
(define-symbol-macro *cm-in* (tidevice-stream-input (current-tidevice)))
(define-symbol-macro *cm-out* (tidevice-stream-output (current-tidevice)))

;; These are for the fildes (needed for system io control (ioctl)

(define-symbol-macro *ifd* (tidevice-ifd (current-tidevice)))
(define-symbol-macro *ofd* (tidevice-ofd (current-tidevice)))

(defun read-some ()
  "Reads input bytes from stdin."
  (let ((sap (sb-sys:vector-sap resbuf))
        (nbytes 0)
        (tmr (sb-ext:make-timer #'exit-repl :name "REPL Kill 2")))
    (tidevice-termios-mode :raw)
    (sb-ext:schedule-timer tmr 15)
    (until *exit-repl-p*
           (setq nbytes (sb-posix:read (tidevice-ifd (current-tidevice)) sap 18))
           (input-push resbuf nbytes)
           (cm-save-cursor)
           (display-vector (length (car *q*)) (car *q*))
           (display-xy)
           (cm-restore-cursor)
           (fill resbuf 0))
    (display-prompt)))


(defun start ()
  (tidevice-termios-mode :libkbd)
  (tidevice-termios-mode :NONL)
  (setup-screen)
  (setq sb-int:*repl-prompt-fun* #'display-prompt)
  (setq *standard-output* *cm-out*)
  (setq *standard-input* *cm-in*)
  (display-prompt)
  )



I cannot get the file descriptor for dup with the synonym streams. and
if I close them SBCL is reluctant to take input.

I also noticed that *stdin* was listed in the code. I have been using a
pty in X windows /dev/pts/1, and /dev/tty on the terminal. These are
working so far, but the many of the terminfo sequences go unnoticed,
such as cm-cursor-to-ll or vpa.

The problem is that everytime I call tput the cursor is moved with the
sbcl prompt. The code does work better in raw mode, but that is a lot of
coding left.

Can I replace *standard-input* with fd-streams?

thanks
steve

[toc] | [next] | [standalone]


#61737

FromLawrence D’Oliveiro <ldo@nz.invalid>
Date2026-10-12 23:23 +0000
Message-ID<11ajq5a$2i7p$1@dont-email.me>
In reply to#61736
On Mon, 12 Oct 2026 17:32:46 -0400, steve g wrote:

> I was interested in changing the REPL for SBCL.

Probably easier to run it in an environment like Jupyter. Even without
a custom SBCL kernel, just the regular “%%script magic” already lets
you do some useful things.

←
    %%script sbcl
    (+ 2 2)
→
    This is SBCL 2.6.4.debian, an implementation of ANSI Common Lisp.
    More information about SBCL is available at <http://www.sbcl.org/>.

    SBCL is free software, provided as is, with absolutely no warranty.
    It is mostly in the public domain; some portions are provided under
    BSD-style licenses.  See the CREDITS and COPYING files in the
    distribution for more information.
    * 4
    *

You probably want to turn off the startup banner message, and the “*”
characters from the default prompting for input by the REPL. The
`--script` option does this, but it also turns off automatic output of
expression values:

←
    %%script sbcl --script
    (+ 2 2) ; produces no output
    (princ (+ 2 2)) ; need to do explicit output
→
    4

This may be OK for running functional scripts, but it is not so
convenient for simple experimentation.

Alternatively, the `--noinform` option turns off the startup banner.
You can then change the prompt to the empty string by setting the
SBCL-specific `sb-aclrepl:*prompt*` variable. To access this, you need
to `require` the `sb-aclrepl` package. To avoid spurious output, this
can all be done with `--eval` options on the command line:

←
    %%script sbcl --noinform --eval "(require 'sb-aclrepl)"  --eval "(setq sb-aclrepl:*prompt* \"\")"
    (+ 2 2)
→
    4

Gets a bit complicated, but at least it’s not always necessary ...

Computing the first n terms of a Fibonacci series:

←
    %%script sbcl --script
    (defvar n 15) ; change as required
    (do
        (
            (a 1 (+ a b))
            (b 1 a)
            (i 0 (+ i 1))
        )
        ((>= i n))

        (format *standard-output* "~A~%" a)
    ) ; do
→
    1
    2
    3
    5
    8
    13
    21
    34
    55
    89
    144
    233
    377
    610
    987

[toc] | [prev] | [next] | [standalone]


#61739

Fromsteve g <Sgonedes1977@gmail.com>
Date2026-10-15 15:06 -0400
Message-ID<8733u6wzqe.fsf@gmail.com>
In reply to#61737
Lawrence D’Oliveiro <ldo@nz.invalid> writes:

> On Mon, 12 Oct 2026 17:32:46 -0400, steve g wrote:
>
>> I was interested in changing the REPL for SBCL.
>
> Probably easier to run it in an environment like Jupyter. Even without
> a custom SBCL kernel, just the regular “%%script magic” already lets
> you do some useful things.
>
> ←
>     %%script sbcl
>     (+ 2 2)
> →
>     This is SBCL 2.6.4.debian, an implementation of ANSI Common Lisp.
>     More information about SBCL is available at <http://www.sbcl.org/>.
>
>     SBCL is free software, provided as is, with absolutely no warranty.
>     It is mostly in the public domain; some portions are provided under
>     BSD-style licenses.  See the CREDITS and COPYING files in the
>     distribution for more information.
>     * 4
>     *



> You probably want to turn off the startup banner message, and the “*”
> characters from the default prompting for input by the REPL. The
> `--script` option does this, but it also turns off automatic output of
> expression values:

Yes. again, this has changed my thinking; --script, like duh! You know
they say the best way to check your documant is by getting someone else
to read it; thank you for this.


> ←
>     %%script sbcl --script
>     (+ 2 2) ; produces no output
>     (princ (+ 2 2)) ; need to do explicit output
> →
>     4

This is very helpful. I did not even think about this.


> This may be OK for running functional scripts, but it is not so
> convenient for simple experimentation.
>
> Alternatively, the `--noinform` option turns off the startup banner.
> You can then change the prompt to the empty string by setting the
> SBCL-specific `sb-aclrepl:*prompt*` variable. To access this, you need
> to `require` the `sb-aclrepl` package. To avoid spurious output, this
> can all be done with `--eval` options on the command line:
>
> ←
>     %%script sbcl --noinform --eval "(require 'sb-aclrepl)"  --eval "(setq sb-aclrepl:*prompt* \"\")"
>     (+ 2 2)
> →
>     4
>
> Gets a bit complicated, but at least it’s not always necessary ...

agreed.


thank you for your spare eyes and your time.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.lisp


csiph-web