From: Corby
Subject: Loading files and running them?
Date: 
Message-ID: <1157424745.049981.292020@m79g2000cwm.googlegroups.com>
I'm using Mac OS X (Intel) and I have done some Scheme programming
years ago.

But now I need to do some Lisp for an AI class, and I have had a hard
time finding a good environment to do this in (the Xemacs site has been
down awhile now, so I can't install it, and I'm really unfamiliar with
emacs anyway).

I installed SBCL using Darwinports and it works fine.  What I want to
do is edit my Lisp program using vim and then load and run it in SBCL.

So I made a simple file called test.l and I start SBCL and type in
(load "test.l") and it returns true.

But then how do I run it and see the output?

-Corby
(······@gmail.com)

From: Corby
Subject: Re: Loading files and running them?
Date: 
Message-ID: <1157425175.548830.41000@e3g2000cwe.googlegroups.com>
Just to clarify... my test.l file just has one line (eq 1 3) which
should return NIL.

And when I do (load "test.l") it returns T, if I do (load
"filethatdoesntexist") it gives an error.
If I do (load 'test.l) it gives an error, and if I do (load '~/test.l)
it gives an error.

-Corby





Corby wrote:
> I'm using Mac OS X (Intel) and I have done some Scheme programming
> years ago.
>
> But now I need to do some Lisp for an AI class, and I have had a hard
> time finding a good environment to do this in (the Xemacs site has been
> down awhile now, so I can't install it, and I'm really unfamiliar with
> emacs anyway).
>
> I installed SBCL using Darwinports and it works fine.  What I want to
> do is edit my Lisp program using vim and then load and run it in SBCL.
>
> So I made a simple file called test.l and I start SBCL and type in
> (load "test.l") and it returns true.
>
> But then how do I run it and see the output?
> 
> -Corby
> (······@gmail.com)
From: Ari Johnson
Subject: Re: Loading files and running them?
Date: 
Message-ID: <m27j0j7yyh.fsf@hermes.theari.com>
I would suggest you get Emacs and SLIME.  I use Carbon Emacs[1] and
Slime from CVS[1] and then include the following lines in my ~/.emacs
(you will have to get slime somewhere useful and put that in the
load-path line and point inferior-lisp-program to sbcl instead of
openmcl; the HyperSpec is handy but optional; you can also put in an
http: URL for it):

(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/slime")
(eval-after-load "hyperspec" '(load "hyperspec-addon"))
(setq inferior-lisp-program
      "/opt/local/bin/openmcl -l /Users/me/.openmcl/startup.lisp")
(setq common-lisp-hyperspec-root "file:/usr/local/share/HyperSpec/")
(setq slime-startup-animation nil)
(setq slime-kill-without-query-p t)
(require 'slime)
(slime-setup :autodoc t)
(add-hook 'slime-mode-hook
  '(lambda ()
     (show-paren-mode t)
     (paredit-mode +1)
     (set (make-local-variable 'lisp-indent-function)
          'common-lisp-indent-function)))
(add-hook 'sldb-hook 'sldb-print-condition)
(setq browse-url-browser-function 'browse-url-default-macosx-browser)
(defun slime-smart-quit ()
  (interactive)
  (when (slime-connected-p)
    (slime-quit-lisp))
  (slime-kill-all-buffers))
(when (eq window-system 'mac)
  (setq mac-option-modifier 'meta)
  (setq mac-command-modifier 'hyper)
  (global-set-key [(hyper s)] 'slime)
  (define-key slime-repl-mode-map [(hyper q)] 'slime-smart-quit))

This makes Cmd-s load Slime and Cmd-q quit it and sets Option as the
Meta key for Emacs.

Regardless of using Emacs, the problems you are having stem from:

"Corby" <······@gmail.com> writes:

> Just to clarify... my test.l file just has one line (eq 1 3) which
> should return NIL.

It should, and it does.  The problem is that you have not given
yourself a way to get at the return value.

LOAD returns true on success, according to the HyperSpec.  If you want
it to display the results of forms it encounters in the loaded file,
you can try (load "test.l" :print t) instead.  However, this is not
the normal way to do things.  The normal way to do things is to define
macros, functions, classes, methods, constants, and global variables
in the files you load and then call those items from the REPL.  For
instance.  In the alternative, you can do (format t "~A~%" (eq 1 3))
to get some output as the forms in the file are executed.

> And when I do (load "test.l") it returns T, if I do (load
> "filethatdoesntexist") it gives an error.
> If I do (load 'test.l) it gives an error, and if I do (load '~/test.l)
> it gives an error.

Common Lisp has two principle types of quotes by default.  Double
quotes surround string literals "like this".  The result of evaluating
a string literal is the string literal itself.  Since LOAD is a
regular function in CL, its arguments are evaluated.  (load "test.l")
therefore evaluates the string to get the same string and then calls
the function LOAD with it as an argument.

The second type of quoting is the single quote mark, which is placed
in front of a single object to prevent it from being evaluated.  It is
actually expanded at read time from 'X to (quote X), and QUOTE is a
special operator which simply returns its argument unevaluated (and it
gets its argument in unevaluated form because it is a special
operator).  So when you do (load 'test.l), you get an error from SBCL
that complains that TEST.L (a symbol) is not of type (OR (VECTOR
CHARACTER) (VECTOR NIL) BASE-STRING PATHNAME STREAM).  In other words,
it wasn't a type that LOAD wanted to deal with.  The same applies to
your attempt with '~/test.l - another symbol, this time named
~/TEST.L, was used.

Anyhow, back to my recommendation that you at least give Emacs and
SLIME a chance - I stand by it.  It will make your Lisping much more
productive.  I do wish I had had such tools at my disposal when I was
required to write Lisp code in college.  Maybe I would have stuck with
Lisp at the time instead of passing it by for so long.

P.S. I am a diehard vim user for life, but I do my Lisp work and some
other things in Emacs because it is just simply better suited to the
task.


1 - www.apple.com/downloads/macosx/unix_open_source/carbonemacspackage.html
2 - ··················@common-lisp.org:/project/slime/cvsroot module slime
From: Berk Birand
Subject: Re: Loading files and running them?
Date: 
Message-ID: <pan.2006.09.05.04.57.04.598896@yahoo.com>
>> But now I need to do some Lisp for an AI class, and I have had a hard
>> time finding a good environment to do this in (the Xemacs site has been
>> down awhile now, so I can't install it, and I'm really unfamiliar with
>> emacs anyway).

I'm exactly in the same situation. I learned scheme when i was a freshman,
and now the parens returned for an AI class. On the other hand I'm using
Linux. Anyway I have vim to write my code, and use clisp (clisp.sf.net) to
run it. 

The way I invoke the interpretor is:

clisp -i main.lsp

this way it executes (compiles) the content  of the file, and keeps the
read-eval-print loop going for you to manipulate that. If you don't want
to interface with the interpretor, then avoiding the -i flag just executes
the file.

As for the return values, only the prints are executed, so you may want to
add in (print ) statements to see what the function returned.

HTH,
Berk

-- 
Posted via a free Usenet account from http://www.teranews.com
From: Jack Unrue
Subject: Re: Loading files and running them?
Date: 
Message-ID: <vtqpf21igm39tdl0ulfjhkqg2h03d3lunr@4ax.com>
On 4 Sep 2006 19:52:25 -0700, "Corby" <······@gmail.com> wrote:
>
> I'm using Mac OS X (Intel) and I have done some Scheme programming
> years ago.
> 
> But now I need to do some Lisp for an AI class, and I have had a hard
> time finding a good environment to do this in (the Xemacs site has been
> down awhile now, so I can't install it, and I'm really unfamiliar with
> emacs anyway).
> 
> I installed SBCL using Darwinports and it works fine.  What I want to
> do is edit my Lisp program using vim and then load and run it in SBCL.
> 
> So I made a simple file called test.l and I start SBCL and type in
> (load "test.l") and it returns true.
> 
> But then how do I run it and see the output?

When LOAD processes a source file, such as your test.l file, it
executes each form in the file and then returns T if the loading
process was successful. If your file simply has the form

  (eq 1 3)

this is executed and the result discarded; there are no side-effects
for you to observe, either directly or indirectly.

A very important detail to be mentioned here is that EQ is
not what you want for this kind of comparison. Use = to
compare two numbers; alternatively use EQUAL.

To make your experiment print something, change your source file
to this

  (print (= 1 3))

and then load it. You should see something similar to

NIL
T

This now has a side-effect that you can see, even though the
result is still discarded.

Now, make a new file test2.lisp (we generally use the extensions
.lisp or .lsp)

  (defun my= (x y) (= x y))

and load it. What did that accomplish? LOAD executed the DEFUN form
which has the side effect of creating a function, in this case
called MY= which you can now call from the REPL

  (my= 1 3)

The REPL evaluates the value returned by MY= which in the case
of a boolean means you will see T or NIL printed.

I won't go any further at this point and talk about interpreted
vs. compiled, and what is load-time, compile-time, or run-time.
Instead, I recommend you find an introductory book, and in fact
I would recommend "Practical Common Lisp" by Peter Seibel.

-- 
Jack Unrue
From: Robert Uhl
Subject: Re: Loading files and running them?
Date: 
Message-ID: <m3lkoys0eh.fsf@NOSPAMgmail.com>
"Corby" <······@gmail.com> writes:

> I'm using Mac OS X (Intel) and I have done some Scheme programming
> years ago.
>
> But now I need to do some Lisp for an AI class, and I have had a hard
> time finding a good environment to do this in (the Xemacs site has been
> down awhile now, so I can't install it, and I'm really unfamiliar with
> emacs anyway).
>
> I installed SBCL using Darwinports and it works fine.  What I want to
> do is edit my Lisp program using vim and then load and run it in SBCL.
>
> So I made a simple file called test.l and I start SBCL and type in
> (load "test.l") and it returns true.
>
> But then how do I run it and see the output?

From the HyperSpec:

  If print is true, load incrementally prints information to standard
  output showing the progress of the loading process. For a source file,
  this information might mean printing the values yielded by each form
  in the file as soon as those values are returned. For a compiled file,
  what is printed might not reflect precisely the contents of the source
  file, but some information is generally printed. If print is false,
  load does not print this information.

  If the file named by filespec is successfully loaded, load returns
  true.

More importantly, the REPL really prints the result of the evaluation of
whatever forms you type in--thus it prints true, since that's the result
of evaluating LOAD.  If you want output from a loaded file you'd do the
same thing as with a function: use PRINT or FORMAT or PRINC or
what-have-you to do so.  The results of individual forms in a file are
no more printed than are the results of individual forms within a
function.

-- 
Robert Uhl <http://public.xdi.org/=ruhl>
Baseball has the great advantage over cricket of being sooner ended.
                                              --George Bernard Shaw