๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by steve g Mon, 12 Oct 2026 21:32
REPL, streams, SBCL
#25
Author: steve g
Date: Mon, 12 Oct 2026 21:32
99 lines
4680 bytes
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
Re: REPL, streams, SBCL
#26
Author: Lawrence Dโ€™Oliveiro
Date: Mon, 12 Oct 2026 23:23
82 lines
3364 bytes
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
Re: REPL, streams, SBCL
#28
Author: steve g
Date: Thu, 15 Oct 2026 19:06
67 lines
3500 bytes
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads