From: Pascal Bourguignon <spam@mouse-potato.com>
Subject: Re: REPL
Date: 04 Dec 2004 13:17:45 +0100 [thread overview]
Message-ID: <873bym9s0m.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: 878y8e48c2.fsf@ID-87814.user.uni-berlin.de
Oliver Scholz <alkibiades@gmx.de> writes:
> [Since M-x ielm has already been pointed to by others ...]
>
> Elvin Peterson <elvin_peterson@yahoo.com> writes:
> [...]
> > IIRC, the REPL code for COMMON LISP is just a couple of lines, so I
> > was hoping someone would post similar stuff for emacs.
>
> Sure, to get a very basic REPL in Emacs is simple:
>
> ;; Because we use `loop' for the looks of it:
> (require 'cl)
>
> (let* ((buffer (generate-new-buffer "*tmp*"))
> (standard-output buffer))
> (switch-to-buffer buffer)
> ;; The REPL:
> (loop (print (eval (read)))))
>
> The extra code in ielm is to get something a tiny little bit more
> comfortable.
Good idea. It could be useful to handle errors, history variables and
termination:
(defvar +++ nil)
(defvar ++ nil)
(defvar + nil)
(defvar /// nil)
(defvar // nil)
(defvar / nil)
(defvar *** nil)
(defvar ** nil)
(defvar * nil)
(defvar - nil)
(defun repl ()
(interactive)
;; I prefer to do it in the current buffer.
(let ((standard-output (current-buffer)))
(switch-to-buffer standard-output)
(block nil
(loop for hist from 1 do
(setf +++ ++
++ +
+ -
- (read))
(insert (format "[%d]> %S\n" hist -))
(when (or (member - '((quit)(exit)(continue))))
(insert "Good bye.\n")
(return))
(setf /// //
// /
/ (list (condition-case G61912 (eval -) (error G61912)))
*** **
** *
* (first /))
(insert (format (format "%%%ds %%S\n\n"
(length (format "[%d]>" hist))) "-->" *))))))
M-x repl RET
[1]> (dotimes (i 5) (if (oddp i) (princ "odd: %d
" i) (princ "even: %d
" i)))
--> (invalid-function 0)
[2]> (princ "toto")
toto --> "toto"
[3]> (dotimes (i 5) (princ (format (if (oddp i) "odd: %d
" "even: %d
") i)))
even: 0
odd: 1
even: 2
odd: 3
even: 4
--> nil
[4]> (/ 5550690 30)
--> 185023
[5]> (quit)
Good bye.
--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
next prev parent reply other threads:[~2004-12-04 12:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-27 18:55 REPL Elvin Peterson
2004-11-27 19:17 ` REPL Maciek Pasternacki
2004-11-27 19:50 ` REPL Marco Gidde
2004-11-28 17:53 ` REPL Elvin Peterson
2004-11-28 21:48 ` REPL Marco Gidde
2004-11-29 11:48 ` REPL Kai Grossjohann
2004-12-04 11:21 ` REPL Oliver Scholz
2004-12-04 12:17 ` Pascal Bourguignon [this message]
[not found] ` <mailman.1833.1101583655.27204.help-gnu-emacs@gnu.org>
2004-11-28 17:55 ` REPL Elvin Peterson
2004-11-28 19:36 ` REPL Pascal Bourguignon
2004-11-28 22:01 ` REPL Marco Gidde
2004-11-29 18:30 ` REPL Elvin Peterson
2004-11-30 21:53 ` REPL Alan Mackenzie
2004-11-30 23:31 ` REPL Joe Corneli
2004-12-02 8:24 ` REPL Friedrich Dominicus
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=873bym9s0m.fsf@thalassa.informatimago.com \
--to=spam@mouse-potato.com \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.