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.
Related
I am just starting out in Tcl and am trying to properly configure an editor and interpreter for use. On Tcl's download page it is recommended to use ActiveState's ActiveTcl, but I am learning Tcl for possible production use and want to avoid paying for it.
I tried setting up Eclipse's DLTK to use for learning, but from what I found I need to direct it to the tclsh executable to use it as the interpreter. In Tcl version 8.6.6, I can't find anything that will work. The supposed formats (I'm on Windows) should follow what's seen here, as I've seen this a few examples/tutorials.
As a last resort, I tried following the Windows instructions here to use my MS Visual Studio 2015 work with this, but there is no such vcvars file (what's asked for when reading makefile.vc after downloading Tcl).
I would really like to use Eclipse for this, so I guess my question is as follows: How do you use tclsh as a Tcl interpreter in Tcl 8.6.6?
ActiveTcl isn't a pay-for product. (ActiveState have some of those, but their language distribution isn't one of them as long as you're not after a support plan.)
To configure Eclipse to use the right installed version of Tcl, go to the Tcl → Interpreters page in the main Preferences panel. That lets you Add… an interpreter, which essentially just requires you to find where the tclsh you want to use is on your filesystem, and to give it a name. I use names like “Tcl 8.6” in my installation, so it isn't exactly rocket science. The DLTK system can find out pretty much everything else once it knows where the interpreter implementation is, but if you have several set up (e.g., I have both 8.5 and 8.6) then you'll need to say which one is default using the checkboxes in the list in the Interpreters pane.
(I've verified the above against Eclipse Neon running on OSX, but I don't think it will vary very much with other versions or platforms.)
In python, I add python and the path of the file, and my script will run.
In haskell, I invoke the GHC compiler on my file to make an executable, or I load GHCi and load the path of the file to use functions, and my script is running.
In Scheme, neither type of approach works for me. Everywhere I search, I only hear about emacs and SLIME. I am not interested in either. I just want to write scripts in notepad++ or any other simple text editor, and either run them through a scheme interpreter, or compile it into an exe, for the purpose of testing code from the MIT SICP book.
I installed MIT/GNU Scheme for learning purposes. I am not interested in Racket because of how different it is from Scheme now (I don't want to confuse myself further, I just want to learn the basics.)
One thing that is contributing to my confusion is the following. When I open mit-scheme through the start menu shortcut, it opens the edwin editor (its tutorial (C-h t command) is apparently "corrupted" so I can't use that instead of notepad++ nor would I want to at this point (just too frustrated with it)). The file location for the edwin editor is in the bin folder. The bin folder though, only has 2 files: mit-scheme.exe and dibutils.dll. If I double-click on mit-scheme.exe it just gives me an error, but apparently using the shortcut opens the edwin editor (that is supposed to be located in the same folder as mit-scheme.exe (it isn't)).
Why is all of this so convoluted? Isn't there a simple way to get my scheme scripts running? I just want to run things like:
(define hello-world
(lambda ()
(begin
(write ‘Hello-World)
(newline)
(hello-world))))
Searching for solutions online was futile for me, I've already wasted many hours- so hopefully I can finally get an answer here.
Thank you.
EDIT: I am on windows 7 and *nix operating systems isn't an option.
mit-scheme has the --load switch. thus
mit-scheme --load path/to/script.scm scrip2.scm -- args ...
I think you also can use Racket to run standard r6rs like this:
plt-r6rs script.scm
For r5rs there is plt-r5rs. Racket can also make executables that run faster with raco exe script.scm.
EDIT
BTW: plt-r6rs is for running programs using the standard R6RS scehem report. plt-r5rs is for running programs using the standadr R5RS scheme report. I have no idea what you mean by "different it is from Scheme". Racket has it's own language, which is the default, which is it's own incompatible dialect of Scheme, but it is not a reason for not using the software. It's like not using gcc because it supports a non standard C++ language and ignoring that you can get ot to behave standard with switches.
There is only one R7RS-small implementation, the reference implementation chibi scheme. Every imlpementation is waiting for the full R7RS report I guess so it's R6RS which is the current standard.
The lists in R5RS and R6RS are mutable (but in R6RS you need to import (rnrs mutable-pairs), but thats a part of the standard. Try not import racket libraries from the standard schemes unless you have no other choice. Check the SRFIs first.
There are not so many Scheme versions and scheme implementations. For every popular programming language that has been for at least 10 years there are more than 3 implementations and several incompatible versions of the standard. If you think there are few implementations of the languages you mentioned you are quite wrong. Python has many implementations and incompatible standard versions. Haskell also has many implementations and versions of their standard. Scheme is from the 70s so it's been around for 40 years so it's only natural that there are more versions of Scheme than Haskell and Python.
This is how I was able to run scheme code from notepad++,
I put to notepad++ run configuration:
"C:\Program Files (x86)\MIT-GNU Scheme\bin\mit-scheme.exe" --heap 512 --library "C:\Program Files (x86)\MIT-GNU Scheme\lib" --load "$(FULL_CURRENT_PATH)"
and then I was able to run. However, I had to save file first, otherwise it is not running. Also notice that (+ 2 2) is not printing as a result, But If I call procedures it is working fine.
sample
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.
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.
What is your Mac OS X (Intel) based lisp setup (of any dialect), how do you like it, and how painful was it to set up? I'm looking for a versatile lisp that is easy to set up, but if you feel strongly about investing more effort, or even money, I would like to hear why you think it's worth it.
I am currently using newLisp, which was a breeze to set up and gives me simple access to things like graphics and sound. I have heard of SBCL with emacs and slime, but that seems a real pain to set up, and I'm still not friends with emacs. I want to see if there's anything I'm missing out on. I would primarily be using this for pleasure, with no commercial goal in mind.
Please recommend only one setup per answer to enable voting, but feel free to submit multiple answers.
Ready Lisp:
Ready Lisp is a binding together of several popular Common Lisp packages especially for Mac OS X, including: Aquamacs, SBCL and SLIME. Once downloaded, you’ll have a single application bundle which you can double-click – and find yourself in a fully configured Common Lisp REPL.
It’s ideal for OS X users who want to try out the beauty of Common Lisp with a minimum of hassle. It could also be used by teachers to give their Mac students a free, complete Common Lisp environment to take home with them.
The best Lisp for Mac OS X is LispWorks. It is commercial though. Installation is done with an installer in a few seconds. It is started then with a double-click from the programs folder. It has a Cocoa-Bridge and the user interface is written with it, but based on a portable substrate - so the same development environment is available for Windows and Unix/Linux/FreeBSD.
I suppose it depends on what you mean by "setup". Clozure CL (previously Open MCL) has an experimental Cocoa bridge, and you can even build a smallish IDE as well (just fire it up and do a (require "COCOA-APPLICATION") and it'll build the .app bundle for you). I use vim myself, but you're free to use whatever editor you like (+ Interface Builder), of course. CCL supports Emacs+Slime, but does not require it.
Try PLT Scheme. It is mature, has lot of libraries and comes with an IDE.
Gambit scheme is a "complete, portable, efficient and reliable implementation of the Scheme programming language":
Gambit consists of two main programs: gsi, the Gambit Scheme interpreter, and gsc, the Gambit Scheme compiler. The interpreter contains the complete execution and debugging environment. The compiler is the interpreter extended with the capability of generating executable files. The compiler can produce standalone executables or compiled modules which can be loaded at run time.
The Gambit compiler allows Scheme to be compiled to C, with some pretty cool applications, like writing an iPhone app in Scheme (with a REPL for remote debugging).
There is a FFI for Gambit so you can use external C libraries.
There is an installer or you can install via MacPorts.
You could install guile. I'd use fink.
That is easy, but it gives you a fairly lightweight scheme installation.
General Comments
Most lisps are not that hard to set up on OS X if you're used to working on the command line, though some are harder than others. I think the hardest to set up are CMUCL and Clozure; if memory serves, you need to make a symbolic link into a directory on your path if you don't want to run them from their respective directories (they don't install an executable into /usr/local/bin on installation). In any case, you'll put more work into getting Slime going in Emacs than you will actually installing a lisp. New Lisp is an easy install from the OS X gui, installed from a OS X package (making it the easiest install of all lisps except, perhaps, for PLT Scheme).
I do recommend using a some form of IDE, be it Emacs + Slime or the LispWorks or Clozure IDEs. People use other editors, but those are the ones that have been tailored most to programming in lisp. Personally, I wouldn't enjoy programming in lisp if I couldn't use Emacs + Slime, but I've put in a lot of time to learn the Emacs and Slime commands.
Implementation Recommendation
Here is a specific recommendation that is different from the others. If you are new to lisp and not too picky that it be Common Lisp, you should look at PLT Scheme. It comes with an IDE and an implementation (DrScheme and mzscheme) that can't be beat for ease of installation and use for a beginner. PLT Scheme comes with lots of extensions to Scheme that make is easier to use for more programming tasks than the other Schemes as well.
Easiest solution: (assumes you have the excellent Mac Ports installed)
Step 1:
$ sudo port install mit-scheme
Step 2:
$ scheme
Step 3:
Read Structure and Interpretation
of Computer Programs http://mitpress.mit.edu/sicp/full-text/book/book.html
Clojure is a wonderful lisp. it is truly modern lisp designed for pragmatic concurrent programming. It compiles to the JVM and can call and be called by java nativity with no wrapping and a minimum of ceremony.
clojure.org
try: XMLisp for OS X (FOSS)
3D: Open Agent Engine: scene graph based mini engine, 3D objects, animation, mouse hovering, selection, camera control, texture management
2D: controls: layout managers, buttons, sliders, text
http://code.google.com/p/xmlisp/
It is an extension of Clozure CL. IDE is included. You should be able to get this running in no time.
Alex