Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

USENET would be a better laboratory if there were more labor and less oratory. -- Elizabeth Haley


devel / comp.lang.lisp / Executing Lisp Scripts In Jupyter

SubjectAuthor
o Executing Lisp Scripts In JupyterLawrence D'Oliveiro

1
Executing Lisp Scripts In Jupyter

<ur8kfs$4icu$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18032&group=comp.lang.lisp#18032

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Executing Lisp Scripts In Jupyter
Date: Thu, 22 Feb 2024 23:14:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <ur8kfs$4icu$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 22 Feb 2024 23:14:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1c30df426ba638bd6ae2f81f1dfd3d68";
logging-data="149918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8jrGBQkYKtlRrpzOEce2I"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:pXWSjKzA1GJfGN8EWe4uN/VYEDA=
 by: Lawrence D'Oliv - Thu, 22 Feb 2024 23:14 UTC

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.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor