tags:

views:

54

answers:

2

I've just downloaded Ready Lisp and am playing around with the REPL. What I want to know is, how do I write a long program, interpret it and get the output? Sort of like what PLT Scheme has.

I'd like to do this with a minimal amount of hassle if that's possible. Just want to get on with the book I'm reading. Thanks.

+2  A: 

Common Lisp provides the functions LOAD and COMPILE-FILE.

  • LOAD will load Lisp textual source code or compiled files and execute those. Any printing done will go to the usual output streams.

  • COMPILE-FILE allows to generate a compiled file from a file with Lisp source code. It has the advantage that the programs are typically running faster when using the file compiler and the compiler does some checking and might give optimization hints. Many implementations will generate native machine code. The file generated with COMPILE-FILE can then be loaded with LOAD.

Note that in Common Lisp one usually uses a running Lisp to compile and load code. In PLT Scheme the model used is that with each 'start' the code gets executed in a fresh Scheme. This may help beginners, but is often a waste of time for writing larger software.

Rainer Joswig
+2  A: 

You open a new file (example.lisp), enter your source code, then do C-c C-c to compile and load a single top-level form, or C-c C-k to compile and load the entire file.

"Compile and load" means that the running image is modified. You do not need to recompile everything after a small modification, but only the defun form in question. You can then switch to the REPL and try it out.

For example, you might enter this form into your source file:

(defun square (n)
  (* n n))

Then, with point at that form, press C-c C-c, switch to the REPL, and try it out:

CL-USER> (square 3)
9
CL-USER>
Svante

related questions