• REPL, streams, SBCL

    From steve g@Sgonedes1977@gmail.com to comp.lang.lisp on Mon Oct 12 17:32:46 2026
    From Newsgroup: comp.lang.lisp


    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

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.lisp on Mon Oct 12 23:23:23 2026
    From Newsgroup: comp.lang.lisp

    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 rCL%%script magicrCY already lets
    you do some useful things.

    raE
    %%script sbcl
    (+ 2 2)
    raA
    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 rCL*rCY 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:

    raE
    %%script sbcl --script
    (+ 2 2) ; produces no output
    (princ (+ 2 2)) ; need to do explicit output
    raA
    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:

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

    Gets a bit complicated, but at least itrCOs not always necessary ...

    Computing the first n terms of a Fibonacci series:

    raE
    %%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
    raA
    1
    2
    3
    5
    8
    13
    21
    34
    55
    89
    144
    233
    377
    610
    987
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From steve g@Sgonedes1977@gmail.com to comp.lang.lisp on Thu Oct 15 15:06:01 2026
    From Newsgroup: comp.lang.lisp

    Lawrence DrCOOliveiro <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 rCL%%script magicrCY already lets
    you do some useful things.

    raE
    %%script sbcl
    (+ 2 2)
    raA
    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 rCL*rCY 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.


    raE
    %%script sbcl --script
    (+ 2 2) ; produces no output
    (princ (+ 2 2)) ; need to do explicit output
    raA
    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:

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

    Gets a bit complicated, but at least itrCOs not always necessary ...

    agreed.


    thank you for your spare eyes and your time.
    --- Synchronet 3.22a-Linux NewsLink 1.2