From: Captain Obvious on
HB> evaluate expression in buffer, play with repl, loading code and
HB> compiling - is there some other way ?

You can even load code from a program itself -- via eval function. This
opens unlimited possibilities.

HB> Loading a file will do for now but I would like to know how to compile
HB> it ? I guess I have to download MinGW or something ?
HB> Can I compile this source code to run it from command prompt ?

Emacs Lisp works only within Emacs, as far as I understand, so there is no
way to do that. There is no need either -- people who use Emacs use it for
everything.

If you want to make a standalone program, you should try Common Lisp or
Scheme instead of Emacs Lisp.

From: Pascal J. Bourguignon on
"Haris Bogdanovic" <fbogdanovic(a)xnet.hr> writes:

> I downloaded the source code for 'Casting spells in Lisp' so wanted to try
> that out. Didn't kniw that I can load a file so it's great, I can now test
> code I write.
> So there are few ways for interacting with code:
> evaluate expression in buffer, play with repl, loading code and compiling -

As mentionned in other answers, you need to distinguish emacs, emacs
lisp, from a Common Lisp implementation you may use such as clisp, sbcl,
etc.

"Casting Spels in Lisp" is written in Common Lisp, and emacs lisp is
different enough that I'd rather bet that code in CSiL would not run
unchanged in emacs lisp. That's why there's a different "Casting Spels
in Lisp -- emacs lisp edition".

In general we will use emacs lisp only to customize emacs. For any
other program we will stay with Common Lisp.

Most CL implementations include a REPL, and the standard CL:LOAD and
CL:COMPILE-FILE functions. Some other way of interacting with the
implementation may be provided either by the implementation itself
(eg. some implementation provide a GUI where you may type expressions
and display results somewhat like with a REPL), or as add-on (eg. you
may write a web server that allows you to evalate lisp expressions (at
least in debugging mode), an example being Uncommon Web). You could
also provide an access to you implementation by writing a telnet server
(for example, you could try Allegro CL with telnet://prompt.franz.com/

So the answer to your question

> is there some other way ?

is YES.


> I use emacs lisp.

We doubt it. That is, unless you're reading "Casting Spels in Lisp --
emacs lisp edition". But if you really "used" emacs lisp, that is,
programmed in emacs lisp, you would rather ask your questions on
news:gnu.emacs.help ;-)

However, emacs provides the same kinds of interaction as the Common Lisp
implementations.

Emacs lisp Common Lisp

REPL: M-x ielm RET ; this is the default
; you launch the
; implementation.

load source: (load "f.el") (load "f.lisp")
M-x load-file RET f.el RET

compile source: (byte-compile-file "f.el") (compile-file "f.lisp")

load compiled: (load "f.elc") (load "f.fas")
M-x load-file RET f.elc RET ; extension may
; change depending
; on the implementation.

When you use emacs as a front end to lisp, you can in both case send
expressions from a buffer to emacs lisp or the "inferior" lisp, that is
to the Common Lisp implementation:

evaluate an (exp) C-x C-e (exp) C-x C-e
expression: ; in an emacs-lisp-mode ; in a lisp-mode
; buffer ; buffer

M-: (exp) RET

Other commands are also available, depending on the interaction mode you
may use (inferior-lisp, slime, etc). In emacs you can get help about
the commands available in the current mode with C-h m



> Loading a file will do for now but I would like to know how to compile
> it ?

See above. Notice also that for lisp "systems", a system definition
facility such as defsystem (old) or asdf (current) or xcvb (future) is
also used, and then compiling or loading the system is done using
functions specific to the system definition facility.



> I guess I have to download MinGW or something ?

No. What use would a C compiler be of?


> Can I compile this source code to run it from command prompt ?

Yes. See above.



I consider that compilation is a late optimization option. When you're
learning a language or developping a new application, you don't need to
compile, because you don't need your programs to run fast. If your lisp
implementation compiles automatically, good. But there's no point in
asking explicitely such an optimization. Concentrate on writing clear
and correct code, test and debug it well.

When it's done and it's time to consider deployment, if it is expected
that the users will have a lot of data to process, then you may consider
proclaiming the optimization declarations and to ask your lisp
implementation to compile the programme. But only if you need it to run
fast.


COMPILE-FILE is an improper function name.
It should have been named OPTIMIZE-FILE-FOR-RUNTIME-SPEED.

--
__Pascal Bourguignon__
From: Haris Bogdanovic on
OK. So I should install slime if I want to program in common lisp.
I saw in slime help document few commands for emacs to install inferior
lisp.
Can someone tell me what exactly to write to install common lisp with slime
?
I'm asking all this question about emacs, should I ask them in a different
newsgroup ?
How can I tell emacs to load some file at startup automatically ?

Thanks


From: Pascal J. Bourguignon on
"Haris Bogdanovic" <fbogdanovic(a)xnet.hr> writes:

> OK. So I should install slime if I want to program in common lisp.

Not necessarily.

emacs -q RET launch emacs without
reading ~/.emacs

C-x b *scratch* RET go to the *scrath* buffer

(require 'cl) C-x C-e to get setf

(setf inferior-lisp-program "clisp") C-x C-e tell inferior-lisp what
lisp you use

M-x inferior-lisp RET launch inferior lisp

C-x 2 split a window

C-x C-f example.lisp RET open a lisp file.

(defun f (x) type in a definition
(if (< x 1) 1 (* x (f (1- x))))) C-x C-e and send it to
the inferior lisp

(f 10) C-x C-e type in an expression
and send it to the
inferior lisp

So you can go a long way without slime.

However, slime provides a lot of nice features you could learn to be
unable to live without. Slime gives a much higher integration between
the emacs user interface and the inferior lisp than the basic
inferior-lisp mode of emacs.


> I saw in slime help document few commands for emacs to install
> inferior lisp. Can someone tell me what exactly to write to install
> common lisp with slime ?

There are a lot of manuals and tutorials and even videos explaining how
to install or use slime. Use google and http://cliki.net/


> I'm asking all this question about emacs, should I ask them in a different
> newsgroup ?

Actually, while slime is an emacs package, questions about slime are
entirely relevant here. After all it's use is (almost exclusively) for
lisp development and it has been written by lisp programmers, so it is
here you will find the best support for slime.


Other questions about emacs concerning its use for lisp programming will
also find an answer here.


Even questions about emacs lisp, as far as they are general lisp
programming questions would find good answers here.

However, any programming languages may be split into three parts:

- a core implementing the basic semantics of the language,
- a "standard" library considered part of the language,
- an ecology of add-on libraries, tools and cultural knowledge
surrounding it.

In the case of emacs, there's a core emacs lisp, there's a "standard"
library which makes it a recognizable lisp. Questions about these parts
could be answered here.

And then there are a lot of libraries, tools, applications and other
features added over emacs lisp to implement the emacs editor, and all
the optional modes, and all the emacs applications such as network
clients (email, erc, news, web, whatever), games, spreadsheets, IDE for
various kind of development and languages, various applications user
inteface front-ends, etc. Unfortunately, most questions about these big
parts cannot be answered here because we may not have the required
knowledge. For example, if you asked a sharp question about writing a
mode, or about using a specific mode such as org-mode, I wouldn't know
anything about it. These questions will be better answered on
news:gnu.emacs.help or one of its brother groups.


> How can I tell emacs to load some file at startup automatically ?

All lisp implementations search for some specific file to load at
startup.

clisp loads ~/.clisprc
sbcl loads ~/.sbclrc
cmucl loads ~/.cmucl-init.lisp
emacs loads ~/.emacs (or ~/.emacs.el)

You can put any lisp expression in these files (emacs lisp expression in
~/.emacs).


You could have learn earlier about this file by reading the manual of
emacs, ie. typing these shell commands:

man emacs
info emacs

Also, you can read info files from emacs with M-x info RET or C-h i



You may start putting:

(require 'cl)
(setf inferior-lisp-program "clisp")

in your ~/.emacs so that you don't have to type and evaluate them again
in the *scratch* buffer next time you start emacs.


--
__Pascal Bourguignon__
From: Haris Bogdanovic on
I put commands from cliki manual to my init.el file.
When I type C-u M-x slime it looks in emacs bin directory and
whatever file I choose I get access denied.
What file should I put in init.el to work with clisp ?

This is what I copied into init.el:

(add-to-list 'load-path "c:/slime")
(require 'slime)
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
;; Optionally, specify the lisp program you are using. Default is "lisp"
(setq inferior-lisp-program "swank-clisp.lisp")

How do I make it to look in the c:/slime directory ?

How do I set default folder for emacs (when I want to open file it goes to
bin folder) ?