• Executing Lisp Scripts In Jupyter

    From Lawrence D'Oliveiro@21:1/5 to All on Thu Feb 22 23:14:05 2024
    It is easy enough to execute a piece of Lisp code inside a Jupyter
    notebook cell: use the “%%script” cell magic on the first line of a
    cell, and the rest of the cell contents will be fed to the command you
    specify. For example, if you have SBCL installed, then executing a
    cell containing just

    %%script sbcl
    (+ 2 2)

    will produce the output “4”, along with the usual SBCL startup
    preamble and interactive prompts. If you don’t want all that, you can
    add the “--script” option. Thus,

    %%script sbcl --script
    (princ (+ 2 2))

    prints out just “4” and nothing else. But you lose the option of
    implicit output, i.e. having the value of the expression printed
    without having to wrap it in a “(princ ...)” call.

    This can be done, but you have to load an extra package to set a REPL
    option, making the “%%script” line a bit more long-winded:

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

    And that does indeed print “4” and nothing else.

    One drawback of the “%%script” magic is that each execution creates a
    new interpreter instance, so you cannot maintain any in-memory context
    from one cell to the next. Another is that it only produces text
    output: you lose access to the rich output options available in the
    Jupyter notebook API.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)