REPL with features of modern shell - shell

I am creating a script (in Lisp, though this can apply to any language with a REPL) which users interface with using the language's REPL. But this does not include even basic interactive features like remembering history. I am wondering if it is possible to tell a terminal emulator to interpret commands using an arbitrary language, instead of the built-in language.
Thanks!

OK, follwoing the advice of user2864740, I looked at GNU Readline, which is the library the provides much of the functionality that I'm looking for. I'm going to switch to Guile Scheme instead of Common Lisp since Guile supports Readline out of the box. However, it looks like it can work in Common Lisp as well: http://www.cliki.net/sb-readline

Yet another approach might be to start the editor emacs, run
M-x shell
and in this shell run your Lisp REPL. You get a lot of feature for free, like command history.

Related

Vim's Ruby option is not enabled

I just started learning Ruby and I ran this command:
vim --version
The output looks like this (look at the yellow circle):
Which means that my Vim does not include the 'ruby' function.
But it seems my Vim supports Ruby fairly well:
q1: Is there any problem with my Ruby programming with the -ruby?
q2: How can I enable Ruby function in Vim?
The functionality on the second screenshot is given by installing the vim-ruby plugin.
The internal Ruby support is to allow people to write plugins and scripts for Vim using Ruby and it's not strictly necessary for what you seem to want to accomplish.
If you REALLY want to add Ruby support, you can always build Vim from source (or get a package with it already built). I suggest you to look into Vim's homepage for more info on this matter.
The difference you are missing is between using Vim to program in a language such as Ruby, and using a given language to program Vim.
Writing Ruby code using Vim is enabled by Vim's native syntax files, as well as various third-party plugins available for Vim. This is the case for many, many languages, not only those mentioned in the :version screen (Perl, Python, and Ruby). You can use Vim to write code in C, Scala, PHP, Javascript, and many other languages, with support for syntax highlighting, smart indenting, and so on.
Writing Vim functions and plugins can only be done in a small set of languages. Natively, Vim code is always written in its own language, Vimscript. However, Vimscript is notoriously difficult to deal with, and most people will not already know it. So Vim also has the ability to use plugins written in other languages, such as Python or Ruby. This enables people to use a more familiar language for plugin development.
However, using those languages requires binding to an interpreter for the language, and this must be decided at the time Vim is compiled. The :version screen is telling you that for your installation of Vim, the Ruby support was not enabled, so you can not write plugins using Ruby, nor can you use any available plugins which were written in Ruby.
Notice that +python is present, so you can use Python plugins (but -python3 is there too, meaning that you do not have Python 3.x support built in).

Using MIT/GNU Scheme

I have downloaded the MIT/GNU Scheme implementation of LISP in order to understand Structure and Interpretation of Computer Programs. However, I am a bit confused about what I am dealing with when I launch the program. When the program is launched, I get two windows: the "MIT/GNU Scheme" window, and the "Edwin: *scheme*" window.
What are these two windows used for? Is the "MIT/GNU Scheme" one some sort of command-line interpreter? While the other is where code can be written and saved?
Further questions: If the MIT/GNU Scheme is a command-line interpreter, how can I get the "1 ]=>" prompt to show. And if the other is where I write programs, how do I test and save the programs?
MIT/GNU Scheme should start off as minimized. It is just a background console window that starts the editor. You need not pay attention to it (nor can you interact with it).
Edwin: *scheme* is the Edwin text editor, which looks to me like some sort of Emacs derivative. It allows you to not only write Scheme scripts but also evaluate Scheme expressions interactively. However, to do this you will need to learn the appropriate keybindings and commands, and some familiarity with Emacs would certainly help here too. Therefore I suggest reading the documentation.

Does Mac OS X come with a Lisp environment built in with Emacs?

I have been trying to find an environment that does not involve installing anything else on my mac for Lisp, as I will not be using it after I get the homework done (who know if I continue using it). I have tried to look but I can't find anything. Anybody know if it does have it, and how to use it within Emacs?
You have a few options for one-click Lisp environments.
If you prefer an Emacs-based environment, check out LispBox. This actually installs a separate instance of Emacs, afaik, so you probably won't have your existing Emacs settings with it.
If you want to use your existing Emacs, SLIME is available both through quicklisp (which you really should be using) or through ELPA.
If you're ok with not having an Emacs environment, and you're not going to be using the language for long, look into LispWorks personal, which has a one-click environment installer in OS X.
If you were actually asking about Scheme (or could go for either Scheme or Common Lisp), take a look at Racket (not technically a Scheme, it actually has a lot of additional features, but they do support R5RS and have a fairly short list of unsupported R6RS features).
Emacs Lisp is rather different from regular Lisp, so it's probably not directly useful for classes or self-study if your target is something like Scheme or Common Lisp. But yes, Emacs has its own Lisp interpreter (or rather, is its own Lisp interpreter). You might want to read up on the differences between Emacs elisp and other dialects / variants to determine whether it might suit your needs.
Clozure CL is a available for free from the Mac App Store
http://itunes.apple.com/us/app/clozure-cl/id489900618?ls=1&mt=12
Have you checked Ready Lisp ?
Also have a look at here.

compile/run Common LIsp from the Mac Terminal

Is there a way to do this? I've been using Slime to learn Lisp, and I would like to start building larger projects which means (I think) that I would have to start writing some .lisp files.
I think your best bets for Mac Common LISP are the LispWorks Personal Edition or SBCL.
Assuming you've got SBCL installed, you can create a .lisp file using a text editor (emacs would be the traditional choice):
(defun test ()
"Hi!")
Then you can run a lisp interpreter in a shell:
bash% sbcl
This is SBCL 1.0.29, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (load "test.lisp")
T
* (test)
"Hi!"
*
The shell could either be a mac terminal window or an inferior lisp interpreter running in emacs.
Slime is designed to support writing Lisp files, including definition finding, online documentation, name completion, compilation, and more. Perhaps you should take a look at the manual, chapter 3 (using slime-mode).
I think it is a bit hard to tell what you are really asking for.
You can compile and load a whole Lisp file in Slime by using C-c C-k in the buffer, and then use it from within the Slime REPL, so you don't even have to run LOAD in the REPL.
Then, there are solutions for shebang lines known from unices that will work in the OS X shell, if you want to run your Lisp programs as scripts from the command line, but those differ from implementation to implementation.
A possibility for building executables, which then can be run from the command line, is loading the relevant code into your Lisp image, then saving that image with the loaded code. Those images may be made executable, executing a given function on startup (think main). This possibility also differs for implementations, so without mentioning your implementation of choice, you will have to look it up in its documentation.
Now, since you are asking about "building larger projects" specifically, my advice would be to get acquainted with a system definition facility. A lisp system basically is a kind of "project", a few files with code, package definitions, and a system definition. I will give you a little example for ASDF, which is (as far as I can tell) the most popular one in the open source world.
(defsystem my-system
:name "my-system"
:version "0.0.1"
:author "hedgehogrider"
:license "BSD"
:description "bla bla bla"
:serial t
:components ((:file "packages")
(:file "code")))
Now, you would put this in an asd file, say my-system.asd, put your package definitions in packages.lisp, your functionality in code.lisp, and then, given you set up ASDF properly, you would be able to compile and load your system in the Slime REPL by pressing ,l my-system. Alternatively, you could enter (asdf:oos 'load-op 'my-system) (or, for more recent versions of ASDF: (asdf:load-system 'my-system)) at the REPL.
In order to make this work, you will have to install ASDF for your Lisp implementation, if it is not shipped with it, and the directory containing your asdf-files will have to be put in asdf:*central-registry*. One easy solution is to symlink your asdf-files to one central directory, but there are other possibilities. Check the ASDF documentation or other tutorials to learn more about ASDF.
Yes, you will want to write your own Lisp files instead of relying on images.
I recommend CLISP for OSX for an out-of-the-box experience. It has a nice REPL experience.
Professional development done with F/OSS today generally uses SBCL or CCL.

something similar to Emacs shell?

I'm looking for something similar to Emacs shell.
I want to be able to select text easily in my terminal, be able to manipulate the output.
Unfortunately, emacs is not always an option. I can't figure out how to make a few things (e.g autocompletion) work the way it does in gnome-terminal and it is a bit of a pain on remote system.
I would rather not spend the time fixing/configuring Emacs unless there is a cool piece of software out there doing something similar to gnome-terminal + let's me manipulate the output without touching the bloody mouse.
Thanks for your help,
-hbt
I'm not sure I completely understand the question, but if you're looking for terminal emulation inside of Emacs, there are at least four options bundled with Emacs 22+ that offer varying levels of xterm-like capability:
term
ansi-term
shell
eshell
eshell, IMO, is the most departed from the tradtional "xterm" experience, but also offers the most buffer-like experience, and it is cross-platform, which is a huge win.
I think shell might be the sweet spot for you if you're looking for term-like behavior, while retaining the editing capabilities.
Finally, term and ansi-term are very term-like, and will behave almost exactly like a xterm/konsole/gnome-shell session.
One other note: if you want scrollback access, copying, pasting, etc. and you don't have Emacs available, I highly recommend learning and using GNU Screen.
You should try the Emacs terminal emulator term(or its colored version ansi-term). There are other terminal emulators for Emacs around, but this is the most popular(and the only one bundled with the default installation).
Looks like you want to look into readline on bash (or if available on your favourite shell). A quick google gives a few links here (including a cheatsheet).
I was also looking for some kind of shell like emacs, with support to some feature like emacs buffers for example. That would be great.
I just found this one: Terminator
Have a look:
http://www.makeuseof.com/tag/5-applications-to-change-the-way-you-work-with-linux-terminal/

Resources