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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With