Groups | Search | Server Info | Login | Register


Groups > comp.lang.lisp > #59394

Executing Lisp Scripts In Jupyter

From Lawrence D'Oliveiro <ldo@nz.invalid>
Newsgroups comp.lang.lisp
Subject Executing Lisp Scripts In Jupyter
Date 2024-02-22 23:14 +0000
Organization A noiseless patient Spider
Message-ID <ur8kfs$4icu$2@dont-email.me> (permalink)

Show all headers | View raw


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.

Back to comp.lang.lisp | Previous | Next | Find similar


Thread

Executing Lisp Scripts In Jupyter Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-02-22 23:14 +0000

csiph-web