I just installed racket-mode in my emacs 24.3, when I run the REPL via racket-repl command, the REPL starts correctly, but some of the racket procedures/functions aren't recognized. i.e
> (class object%)
; class: undefined;
; cannot reference undefined identifier
> (enter! "test.rkt")
; enter!: undefined;
; cannot reference undefined identifier
The current value of the racket-racket-program variable is set to Racket.exe. On the other hand if I just run Racket.exe from the windows command line, then the REPL works as expected.
Any help with this is greatly appreciated.
When you do a racket-repl, that REPL initially opens with the equivalent of #lang racket/base. At the prompt you could type (require racket) to get the bigger language, including the class stuff like object%.
(There's an open issue about this. Feel free to chime in there.)
Instead of typing (enter! "test.rkt") at the prompt, try ,run test.rkt.
In fact, the easiest way to do this is with an Emacs buffer open on test.rkt. Then you can press C-c C-k a.k.a. M-x racket-run.
(Note that this leaves point in the test.rkt buffer. If you prefer point to go to the REPL, instead you can use M-x racket-run-and-switch-to-repl, bound by default to F5 like in DrRacket.)
TL;DR the most common use pattern with racket-mode is:
Visit a .rkt file in a buffer.
"Run" it with C-c C-c (or F5).
Explore in the REPL interactively as you wish.
Goto 2.
If your file contains #lang racket then the REPL picks up what language to use.
If no such line is present my guess is that racket/base is used -- and object% is not defined in racket/base.
Try entering this program:
#lang racket
(+ 1 2)
Then start the REPL and try your snippet again.
Related
I use paredit on emacs with SLIME's repl. This means that at any point during my typing on the repl, my s-expressions are balanced.
However, they may not be complete, and I might want to continue typing inside them in another line, as follows:
CL-USER> (defun print-hello ()
)
When I start a new line by pressing the enter key, however, the SLIME repl executes my incomplete expression. I want it to wait for me to complete the expression, as follows:
CL-USER> (defun print-hello ()
(format t "Hello, world"))
How do I make this happen please?
For that situations, when writing long s-expressions in REPL I think that the best way is to use the slime scratch buffer. you can edit it and after that execute with
C-j
No problem pressing enter inside the buffer, I'm using sly but the capture could be like this:
(defun print-hello ()
(format t "Hello, world"))
; => PRINT-HELLO
Also another alternative is working without the last parent :-(
or as suggested in a comment by #jkiisky, type the expression and add in the middle of the s expression C-j
CL-USER> (defun
)
Related to your question, lispy provides integration with SLIME.
I typically never type anything into the REPL buffer. Instead, I edit all code in place in the source file, and use e to eval the current sexp.
lispy is also a super-set of paredit, if compatibility is your concern.
I've seen hits all around this basic issue, but nothing to help with, in particular, plai-typed. So, I can start a racket REPL in geiser, then type (require typed/racket) and it seems to take, i.e., I'm ready to go with basic typed racket. Normally, typed/racket is activated by having #lang typed/racket at the top of a source code file, then loading it. Likewise #lang plai-typed is how to use the specific "Programming Languages Applications Interpretations" racket language in source code. But then how can I switch to the plai-typed language in a running geiser racket REPL? Even better would be how to do this in an org-mode babel source code block.
In a Geiser REPL buffer, you could do C-c C-m plai-typed to get access to the plai-typed language. Additionally, if you're working with a Racket file, you could open that file in Emacs with C-x C-f /path/to/foo.rkt and then do C-c C-a to load the file into a Geiser REPL (it will create a new one if there is no existing REPL). This has the same effect as C-c C-m, but it will also run any code in the file. Note that the C-c C-a approach won't work in non-file buffers because the geiser-mode-switch-to-repl-and-enter function uses the Geiser ,enter command and it tries to supply ,enter with a path, which obviously won't work if you're in a buffer that's not associated with a file.
I'm starting to play with CLisp, and therefore Emacs too, including the "SLIME" plugin (or whatever it's called. How is it called?)
So I've been playing with the REPL for quite some time now, and defined a lot of functions in there with (defun).
Unfortunately, none of these functions have been written in a text file, and I don't fancy retyping all that. Is there a way I could dump or otherwise save the work that has been done in the REPL to a file? (bonus points if the file is Lisp source code :) )
SLIME is an elisp program for interacting with Lisp.
There's no simple option to recover functions you've typed only into the repl into a file. function-lambda-expression can sometimes return code, but it often does not.
If the repl is still in a buffer, you could copy the whole thing into a file and then use string or regexp replacement to isolate the function definitions.
It's not too hard to avoid this problem in the future.
Most people work by writing definitions into a file, and then using a key combination to send them to Lisp, bypassing the REPL. I use the C-c C-c combination when the cursor is on a function to compile and load the expression. C-x C-e also works. Then I switch the the REPL to actually use the function.
See also the function DRIBBLE, which makes sure a log is written.
foo:~$ clisp
...
[1]> (dribble "foo.text")
#<OUTPUT BUFFERED FILE-STREAM CHARACTER #P"foo.text">
[2]> (+ 3 4)
7
[3]> (defun bar (baz) (* baz baz))
BAR
[4]> (bar 10)
100
[5]> (quit)
Bye.
Let's look at the file:
foo:~$ more foo.text
;; Dribble of #<IO TERMINAL-STREAM> started on 2015-05-08 21:38:48.
#<OUTPUT BUFFERED FILE-STREAM CHARACTER #P"foo.text">
[2]> (+ 3 4)
7
[3]> (defun bar (baz) (* baz baz))
BAR
[4]> (bar 10)
100
[5]> (quit)
Bye.
The last paragraph in Xach's answer is what it is all about.
When programming in Lisp, typing function definitions directly into the REPL is the wrong way to do it. The right way is to set up your text editor (emacs) so that with certain keystrokes, the expression at the cursor (the entire function definition) is sent to the REPL. Then to invoke a function, you switch to the REPL. This is what SLIME is for.
Strictly speaking, the text in your emacs buffer doesn't have to be written to a disk file, in which case it will be gone after you close the editor. But normally you save it to a file.
You can search through your REPL history for the function definitions. If you have the beginning of an expression already typed in, then SLIME will only cycle through previous entries that begin with the same thing:
CL-USER> (defun
Press M-P from there, and you'll cycle through all the defuns you've typed in.
I'm a newbie to LISP.
I am attempting to invoke the scheme interpreter from within emacs (version 23 running on windows). I loaded the xscheme library by telling emacs to M-x load-library and then entering xscheme at the prompt in the minibuffer. The library loaded, and then I issued the M-x run-scheme command. (I realize that all this loading can be done from .emacs at startup, but I am not concerned with that at the moment.)
So far so good - the *scheme* buffer has been created, and now I'm hoping that I'm able to talk to the scheme interpreter.
However, when I try to evaluate something in that *scheme*buffer (e.g. (define shoe-size 14)), I get this Output file descriptor of scheme is closed message in the minibuffer.
Does anybody know how to fix this in emacs?
(Also, how does one set the major-mode as REPL in the *scheme* buffer?)
Thank you.
Try setting the scheme-program-name variable to the path to your Scheme interpreter. The major-mode of the scheme buffer is probably just comint and you cannot do much about it unless you switch to something more capable like Geiser - something that I'd recommend you do.
Add this line to your .emacs file:
(setq scheme-program-name "gsi")
(Replace "gsi" with the name of your Scheme interpreter.)
You can then start the interpreter with M-x run-scheme. You can evaluate pieces of code by using C-x C-e (to evaluate the sexp before the point) or with C-M-x to evaluate the sexp you're in right now. You can also load a file with C-c C-l.
I'll start by saying that I'm very new to programming, scheme and SICP, but I'm trying to work through the course and watch the lectures that are online.
I'm running emacs on Ubuntu 12.10 and I really wanted to get MIT scheme working in emacs instead of relying on Edwin.
The above tips didn't work for me, but here's the step-by-step instructions that did work:
Install emacs 24 from the Ubuntu Software Center (search "emacs" and install it!)
Open a terminal (ALT + CTRL + t)
Go to your home directory (cd ~)
Open the hidden file .emacs in gedit (gedit .emacs)
On the first line of the file, type exactly what's after the colon: (require 'xscheme)
Save the changes to .emacs
That's it!!!
You can now open .scm files in emacs and use commands like C-x C-e.
*directions courtesy of http://alexott.net/en/writings/emacs-devenv/EmacsScheme.html#sec14
My guess is that it's just a known issue I still dunno how to sort that out (it's out of my current skills) but I got a macro that probably helps: just after writing the s-exp you can do Cc-Cz (it calls the geiser REPL) then C-spc, C-M-b, M-w, C-x-o, C-y and RET.
There are a variation (same, placed just after writing the s-exp): C-spc, C-M-b, M-w, C-c Cz, C-y and RET
Situation: I entered several functions while working with REPL in Emacs.
Problem: There is junk like "; Evaluation aborted" when I'm simply saving buffer.
What I want: clear descriptions of all the functions I entered in their latest revision.
Can I do that? Thanks.
I don't get it. Are you entering definitions at the REPL and expecting to recover them later? Just save a source file as you would in any other language. Use C-x 2 to split your Emacs window in two. Open a source file in one of them C-x C-f foo.lisp. Use C-c C-k, C-c C-r and friends (see SLIME menu) to compile / evaluate regions of your source code in the REPL.
I've looked for something like this in the past and have been unable to find it. You're best off writing all your definitions in a separate buffer and using SLIME's extensive evaluation/compilation functions (C-c C-k loads an entire file, C-x C-e evaluates the last expression, C-c C-r evaluates a region, etc.), only directly entering into the REPL things you don't want to save.
Um, C-x o or C-x b to get to the SLIME REPL buffer, then C-x w or C-x C-s to save it to a file. All the SLIME/CL stuff is a reader comment; you can either write a reader hack to reload the file treating the prompts as comments, or you can go through the file yourself to capture the pieces you want to save.
I agree that the best work flow method is to write your code in a separate buffer and evaluate in that, rather than enter the functions in the repl.
Assuming you have gone the repl way, I guess, C. Martin's solution to save the repl log and manually go through it are your only options.
If you entered the functions and vars into a separate package, you could go through the symbols in the package to help you decide what you want to keep.
E.g. to see all symbols created in the cl-user package:
(let ((p (find-package :cl-user)))
(loop
for s being the symbols in p
when (eq p (symbol-package s))
do (format t "~a~%" s)))