Paste number 89718: Multiple Common Lisp Implementations on Win32 + ASDF setup HOWTO

Index of paste annotations: 1 | 2

Paste number 89718: Multiple Common Lisp Implementations on Win32 + ASDF setup HOWTO
Pasted by: fusss
When:2 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+1X86
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
;;;--------[ Multiple Common Lisp Implementations on Win32 + ASDF setup HOWTO

;;;--[ #x01 Get Emacs

http://ntemacs.sourceforge.net/

Install somewhere in your harddisk, preferably in C:\emacs

Emacs configuration file is .emacs, pronounced dot-emacs, and it's in C:\.emacs

Add it to your path (Windows XP instructions):
Right click on My Computer icon on desktop --> Properties --> Advanced 

Click on the "Environmental Variables" button just above the "OK" button.

In User Variables, scroll down to PATH, highlight, click "Edit", then type the path your
emacs binary directory, C:\emacs\bin, make sure to sperate it from the other items by a semi colon.

To test it, fire up a new DOS Command button, and type:

C:\echo %PATH%

See if emacs is in your path.

;;;--[ #x02 Get multiple Lisps

Having various Common Lisp implementations allow you to experiment.

SBCL:
http://www.sbcl.org/  or  http://ntemacs.sourceforge.net/

Closure Common Lisp:

http://trac.clozure.com/openmcl/browser/release/  [pick the latest version]
For Closure you just need two files, wx86cl.exe and wx86cl.image for 32-bit Windows or
wx86cl64.exe and wx86cl64.image for 64-bit Winddows

CLISP:

https://sourceforge.net/project/platformdownload.php?group_id=1355&sel_platform=8418

Install them all in simple directories in your root, just C:\sbcl, C:\ccl and C:\clisp.

;;;--[ #x03 Get SLIME

http://common-lisp.net/project/slime/

CVS snapshot is usually at http://common-lisp.net/project/slime/snapshots/slime-current.tgz

Extract it to C:\slime

;;;-- [ #x04 Edit your .emacs file

Below you will be editing your .emacs file. It has a line for the Lisp implementation you want to use by default
and this is the line you will be editin the most.

Edit your C:\.emacs file and add this to it:


  ;; SLIME
  (add-to-list 'load-path "C:/slime/")  ; your SLIME directory
  ;(setq inferior-lisp-program "C:/sbcl/sbcl.exe --core C:/sbcl/sbcl.core --sysinit C:/sbcl/sbclrc"	
  (setq inferior-lisp-program "C:/ccl/wx86cl.exe -l C:/ccl/cclrc.lisp")
  ;(setq inferior-lisp-program "clisp -i C:/clisp/.clisprc")
  (require 'slime)
  (slime-setup '(slime-fancy slime-asdf slime-banner))


The lines that begin with semi-colons are comments. You see that there are three lines that have 
(setq inferior-lisp-program ..) those choose which Lisp you want to run. In my case, the first two are commented
out and the third is not, because I am currently using Closure Common Lisp.

You can pass command-line arguments to your Lisp implementation via this Emacs interface; CLISP is called with a
C:\clisp\.clisprc configuration file, sbcl with a path to a core file and a configuration file C:\sbcl\sbclrc,
while Closure's configuration file is C:\ccl\cclrc\.lisp.

Nearly all Lisps understand Unix-style forward-slash paths. This is to avoid the double quoting; you can supply Win32
paths but you will need to do something like C:\\clisp\\.clisprc. Stick to Unix paths on Win32 and you should be fine.


;;;-- [ #x05 Establishing an ASDF policy.

SBCL ships with ASDF, but all others don't. ASDF is the de facto Common Lisp package management tool, it's just one
lisp file, asdf.lisp, but it's floating around in various forms, usually customized for a specific Lisp implementation.

My policy is to share 3rd party libraries and packages among all Lisps, EXCEPT ASDF. For ASDF, you are better off using 
the version most specific to your implementation.

Luckily, CLISP and Closure can use the standard ASDF version.

Generic ASDF is available in http://www.cliki.net/asdf with the downloadable tarball at:
 http://common-lisp.net/project/asdf/asdf.tar.gz

For this setup we will keep all Lisp packages in one directory, C:\lisplibs, but you can call it whatever you want.
Create that directory as well.

From now on, whenever you download a Lisp library, extract it to C:\lisplibs, and make sure each library is inside
its own directory. Don't extract naked files into the same directories; Lisp libraries have files with identical names
and will overwrite each other. The package.lisp file is found in most libraries, and it's not shareable. You overwrite
one, you lose.

We will now setup and launch the various Lisps one by one.


;;;-- [ #x06a Setup SBCL

Add your C:\sbcl SBCL directory to your path, as you did for Emacs in #x01.

Open a new DOS command window and type "sbcl", see if it's working right. Close it with Control-c or type (quit)
at the Lisp shell.

Open your .emacs file and comment out (put a semi-colon before) all the (setq inferior-lisp-program ..) except this:

 (setq inferior-lisp-program "C:/sbcl/sbcl.exe --core C:/sbcl/sbcl.core --sysinit C:/sbcl/sbclrc")
 
You will need to make sure the files supplied to SBCL exist; sbcl.core should be there, but we will need to create sbclrc.

Create the file C:/sbcl/sbclr and put this in it:

  (require :asdf)

  (dolist (dir (directory "C:/lisplibs/*/"))
    (pushnew (make-pathname :directory  (pathname-directory dir) :type "asd")
	   asdf:*central-registry*))

This loads the ASDF library management tool, and also finds out where your 3rd party Lisp libraries are. On Unix,
there is a single sbcl/site-systems directory where symbolic links to the library files (*.asd files) are kept. In Windows
we need to read the directory directly and add the paths to our central registry.

You can also add your own libraries to the central registry, I usually have this form as well:

   (push #p"C:/hacks/" asdf:*central-registry*)

You can add any directory to your ASDF central registry, but don't forget the path to the directory ends with a /.

Excellent!

Now fire up Emacs and type M-x slime

That's, press 'x' while holding the ALT key, and type slime then press ENTER.

Text should start scrolling by as Slime is compiled for SBCL and other magic happens. At the end of it, you will 
see what will become your new home, the slime repl!

  ; SLIME 2009-10-12
  CL-USER> 


;;;-- [ #x06b Setup Closure Common Lisp

It's the same thing. Edit your C:\.emacs file and comment out the inferior-lisp-program lines for sbcl and clisp.
Un comment the one for CCL.
 
  (setq inferior-lisp-program "C:/ccl/wx86cl.exe -l C:/ccl/cclrc.lisp")

Closure expects C:\ccl\cclrc.lisp initialization file. However, the DIRECTORY function in Common Lisp is not required
to return a directory listing or accept wild flags, so Closure's implemenation doesn't. There are 3rd party libraries
to remedy this, CL-FAD being my favorite.

So here is what I do:

  (require :asdf)

  (dolist (dir
	  (list #P"C:\\clisp\\zpng\\" 
                #P"C:\\clisp\\zpb-ttf\\"
                #P"C:\\clisp\\zlib\\"
		#P"C:\\clisp\\wildcard\\"

		;-- add more here
		))
     (pushnew dir  asdf:*central-registry*))

Add the path to each library you install in that list, in that format. Better yet, learn how to use CL-FAD. Mine is
actually auto-generated with CL-FAD, you can tell by the reverse-alphabetical listing of the files ;-)
  
Restart Emacs, and if you have commented out the CLISP and SBCL lines, Closure should fire up and start compiling Slime.

;;;-- [ #x06c Setup CLISP

CLISP is also the same.

Comment out the SBCL and CCL lines, uncomment CLISP's, and put this in your C:\clisp\.clisprc file

  (require :asdf)

  (dolist (dir (directory "C:/lisplibs/*/"))
    (dolist (asd (directory (make-pathname :directory dir :type "asd")))
      (pushnew asd asdf:*central-registry*)))

Annotations for this paste:

Annotation number 1: more convenience
Pasted by: meh
When:2 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+1X86/1
Paste contents:
Raw Source | Display As
;;;___usage_____________________________________________________________________

M-x slime    starts slime with the default lisp implementation (see below)
M-x ccl      starts slime with ccl 
M-x sbcl     starts slime with sbcl
M-x clisp    starts slime with clisp

If an envirinment variable %home% is defined, all startup files may be placed there (i.e. ccl-init, .clisprc, .sbclrc).

All .asd system definitions in a direct subfolder of the library path are available to asdf (i.e. library/folder/*/*.asd), meaning to install a library simply extract the archive in the library folder in most cases. 

;;;___configuration_files:______________________________________________________

;;___in_.emacs__________________________________________________________________

;;;; SLIME Setup
(add-to-list 'load-path "path/to/slime")
(require 'slime)

;; default lisp implementation goes first in this list, functions to start each are generated on startup
(setq slime-lisp-implementations
      '((sbcl ("path/to/sbcl.exe"))
        (ccl ("path/to/wx86cl.exe")) ; or wx86cl64.exe
        (clisp ("path/to/clisp.exe"))))
(setq slime-net-coding-system 'utf-8-unix)
(slime-setup '(slime-fancy slime-asdf slime-banner))


(defun cliki:start-slime ()
  (unless (slime-connected-p)
    (save-excursion (slime))))
(add-hook 'slime-mode-hook 'cliki:start-slime)

(defun slime-lisp-implementations-fun (name)
  (eval `(defun ,name ()
           (interactive)
           (apply 'slime-start
                  (list* :buffer (concat "*inferior-lisp-"  
                                         ,(symbol-name name) "*")
                         (slime-lookup-lisp-implementation 
                          slime-lisp-implementations ',name))))))

(mapcar 'slime-lisp-implementations-fun (mapcar 'car slime-lisp-implementations))

;;___ccl-init___________________________________________________________________
;; put in %USERPROFILE%

(setf ccl:*default-file-character-encoding* :utf-8)
(setf ccl:*default-socket-character-encoding* :utf-8)

#-:asdf (require 'asdf) 
(load #p"path/to/asdf-setup.lisp")

;;___.sbclrc____________________________________________________________________

#-:asdf (require 'asdf) 
(load #p"path/to/asdf-setup.lisp")

;;___.clisprc___________________________________________________________________

#-:asdf (load #p"path/to/asdf/asdf.lisp")
(load #p"path/to/asdf-setup.lisp")

;;___asdf-setup.lisp____________________________________________________________

;; An alternative to the standard sysdef search can be defined.  This 
;; code below can be dropped into your Lisp init files and customized. 
;; It will search for all ASDF systems in subdirectories of the 
;; specified directories.  That lets you simply "drop-in" new packages 
;; into one of the specified directories, and it will be available for 
;; loading without any further steps. 

(in-package #:asdf)
(defvar *subdir-search-registry* '(#p"path/to/library/folder")
  "List of directories to search subdirectories within.")
(defvar *subdir-search-wildcard* :wild
  "Value of :wild means search only one level of subdirectories; value of :wild-inferiors means search all levels of subdirectories (I don't advise using this in big directories!)")
(defun sysdef-subdir-search (system)
  (let ((latter-path (make-pathname :name (coerce-name system)
                                    :directory (list :relative
                                                     *subdir-search-wildcard*)
                                    :type "asd"
                                    :version :newest
                                    :case :local)))
    (dolist (d *subdir-search-registry*)
      (let* ((wild-path (merge-pathnames latter-path d))
             (files (directory wild-path)))
        (when files
          (return (first files)))))))
(pushnew 'sysdef-subdir-search *system-definition-search-functions*)

Annotation number 2: asdf-install notes
Pasted by: ayrnieu
When:2 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+1X86/2
Paste contents:
Raw Source | Display As
http://robert.zubek.net/blog/2008/04/09/sbcl-emacs-windows-vista/#comment-5

Copied here:

Also, here are some notes for getting ASDF-install to work with SBCL and Windows. They weren't worth their own blog posting, really.  

It's tricky to get asdf-install to work in a Windows SBCL installation, due to a combination of reliance on Unix tools for archive processing, and some problems with inter-process communication on the Windows port of SBCL. 

This produces errors such as the following, when trying to run asdf-install:

CL-USER> (asdf-install:install 's-xml-rpc)
...
couldn't fork child process: No such file or directory
[Condition of type SIMPLE-ERROR]
...
Backtrace:
0: (RUN-PROGRAM "tar" ("-tzf" "c:\\Program Files\\emacs-22.2\\bin\\S-XML-RPC.asdf-install-tmp"))

Here's a method to get this up and running. The following was done using SBCL 1.0.13 and a recent version of ASDF-Install, all running on a Windows Vista machine. 

I. The tools

First, get a copy of ASDF-Install from the "asdf-install-unstable" repository:
http://common-lisp.net/project/asdf-install/asdf-install_latest.tar.gz

SBCL comes with its own, older version – I just installed this new one right on top of the old one, in the sbcl/asdf-install directory.

Second, you'll need Cygwin, for the bash and tar programs from Unix. Plus, it's a very cool toolset. 
http://www.cygwin.com

II. The kluges

Now time for some diffs. 

First of all, in asdf-install/variables.lisp, customize the paths to match your Cygwin install. In particular, the following: (changed lines in boldface)

#+(or :win32 :mswindows)
(defvar *cygwin-bin-directory*
  (pathname "C:\\Cygwin\\bin\\")) ;; CHANGED

#+(or :win32 :mswindows)
(defvar *cygwin-bash-program*
  "C:\\Cygwin\\bin\\bash.exe")    ;; CHANGED

Second, in asdf-install/installer.lisp, in the function tar-arguments, we get rid of extra backslashes and double quotes:

(defun tar-arguments (...)
...
#+(or :win32 :mswindows)
(list "-l" "-c"
      (format nil
              "tar -C `cygpath `~A'` -xzvf `cygpath `~A'`"  ;; CHANGED
              (namestring (truename source))
              (namestring (truename packagename))))

Finally, a change in asdf-install/port.lisp: the function return-output-from-program has got to lose its output redirection, because it confuses Win32 SBCL. (In effect, it will no longer return any output from program, but be that as it may.  ) The new version looks like:

(defun return-output-from-program (program args)
  (with-output-to-string (out-stream)
    (let ((proc (sb-ext:run-program
                 program args :search t :wait t)))
      (when (or (null proc)
                (and (member (sb-ext:process-status proc) '(:exited :signaled))
                     (not (zerop (sb-ext:process-exit-code proc)))))
        (return-from return-output-from-program nil)))))

3. The results. 

Now everything should be ready to run. 

CL-USER> (require 'asdf-install)
CL-USER> (asdf-install:install 's-xml-rpc)

A few additional notes:

1. At the "Install where?" prompt, it's easiest to install to the local directory. System-wide install will fail because of Vista user-access control, unless you're running your Lisp session as root.  

2. GPG verification isn't supported on Win32 SBCL, and would require more kluging.

3. ASDF by itself expects all definition files to be linked manually to the repository directory. For a quick script to automate that, see this page: http://www.cliki.net/asdf – under the Alternative Sysdef Search functionality heading.

Colorize as:
Show Line Numbers
Index of paste annotations: 1 | 2

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.