From: Jan Wedekind <jan@wedesoft.de>
To: guile-user@gnu.org
Subject: Artanis web REPL
Date: Fri, 24 Jun 2016 12:43:29 +0100 (BST) [thread overview]
Message-ID: <alpine.DEB.2.11.1606241239490.29787@wedemob> (raw)
Just managed to get a simple web REPL working. It still needs some form of
safe environments for each browser sessions. Maybe one can do something
like the IPython notebooks in the future.
Any comments/suggestions welcome.
; prototype Guile repl for the browser
(use-modules (srfi srfi-26) (artanis artanis) (artanis cookie) (artanis utils) (ice-9 regex))
(init-server)
(define (dot lst) (apply cons lst))
(define (quoted expr) (call-with-output-string (cut write expr <>)))
(define (line-breaks s) (regexp-substitute/global #f "\n" s 'pre "<br/>" 'post))
(define lines '())
(define (reset session)
(set! lines (assoc-set! lines session '()))
(output session (format #f "; session: ~a~&" session)))
(define (output session line)
(assoc-set! lines session (cons line (assoc-ref lines session))))
(define (repl session line)
(catch #t
(lambda ()
(output session line)
(let [(result (eval-string line (current-module)))]
(if (not (unspecified? result))
(output session (format #f "; ~a~&" (quoted result))))))
(lambda (key function fmt vals . args)
(let* [(msg (apply format #f fmt vals))
(info (format #f "; ~a" msg))]
(output session info)))))
(define (editor session)
(tpl->response
`(html
(body
,(map (lambda (line) `(p ,(line-breaks (eliminate-evil-HTML-entities line)))) (reverse (assoc-ref lines session)))
(form (@ (action "") (method "post"))
(input (@ (type "text") (name "line") (autofocus "autofocus"))))))))
(get "/" #:session 'spawn
(lambda (rc)
(let [(session (:session rc 'spawn))]
(reset session)
(editor session))))
(post "/"
(lambda (rc)
(let* [(session (cookie-ref (rc-cookie rc) "sid"))
(post-data (map dot (generate-kv-from-post-qstr (rc-body rc))))
(line (uri-decode (assoc-ref post-data "line")))]
(repl session line)
(editor session))))
(run)
next reply other threads:[~2016-06-24 11:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 11:43 Jan Wedekind [this message]
2016-06-24 17:20 ` Artanis web REPL Nala Ginrut
2016-06-24 21:40 ` Jan Wedekind
2016-06-24 21:51 ` Jan Wedekind
2016-06-25 1:14 ` Nala Ginrut
2016-06-25 20:09 ` Jan Wedekind
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.11.1606241239490.29787@wedemob \
--to=jan@wedesoft.de \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).