From: David Steuber
Subject: How do I deal with &optional args?
Date: 
Message-ID: <87isfpumd3.fsf@david-steuber.com>
Given this function:

(defun create-swank-server (&optional (port +server-port+)
                            (background *communication-style*)
                            (announce-fn #'simple-announce-function)
                            dont-close)
  (setup-server port announce-fn background dont-close))

I want to call create-swank-server with a specified port and
dont-close.  In C++, I would be forced to also set background and
announce-fn even though they have defaults because these are
positional arguments.  Do I have to do the same in Lisp?  Or can I do
this:

(swank:create-swank-server port dont-close)

I tried this:

* (swank:create-swank-server 4005 t)
;; Swank started at port: 4005.

But I did not get back to a REPL prompt (SBCL on x86 Linux).  So I
don't really know if the right thing happened or not.  I want to start
up SBCL with a shell script that has this in it:

/usr/bin/detachtty --dribble-file /home/david/usr/var/run/lisp-dribble \
                   --log-file /home/david/usr/var/run/detachtty.log \
                   --pid-file /home/david/usr/var/run/lisp.pid \
                   /home/david/usr/var/run/lisp-socket  \
                   /home/david/usr/bin/sbcl \
                     --eval '(asdf:operate 'asdf:load-op 'modlisp)' \
                     --eval '(asdf:operate 'asdf:load-op 'cl-ppcre)' \
                     --eval '(asdf:operate 'asdf:load-op 'lml2)' \
                     --eval '(asdf:operate 'asdf:load-op 'swank)' \
                     --eval '(ml:modlisp-start :port 3000)' \
		     --eval '(swank:create-swank-server 4005)'

So the last --eval arg would be changed to reflect what I did in the
REPL.

When I made an HTTP request, I didn't connect to SBCL.  M-x
slime-connect failed also.

I also tried the last --eval like this:

--eval "(swank:create-swank-server 4005 swank:*communication-style* #'swank:simple-announce-function t)"

I couldn't connect.  When I ran attachtty, I got a debugger prompt
sans options.  So I was stuck again.

I'm trying to setup SBCL so that I can connect and disconnect with
SLIME at will and also have it talk to Apache when started with a
shell script.

-- 
I wouldn't mind the rat race so much if it wasn't for all the damn cats.

From: Raymond Wiker
Subject: Re: How do I deal with &optional args?
Date: 
Message-ID: <86wu45t6do.fsf@raw.grenland.fast.no>
David Steuber <·····@david-steuber.com> writes:

> Given this function:
>
> (defun create-swank-server (&optional (port +server-port+)
>                             (background *communication-style*)
>                             (announce-fn #'simple-announce-function)
>                             dont-close)
>   (setup-server port announce-fn background dont-close))
>
> I want to call create-swank-server with a specified port and
> dont-close.  In C++, I would be forced to also set background and
> announce-fn even though they have defaults because these are
> positional arguments.  Do I have to do the same in Lisp?  Or can I do
> this:
>
> (swank:create-swank-server port dont-close)

        Won't work... you have to explicitly specify all parameters up
tom and including the last parameter you want to set -just like in
C++. Keyword parameters would probably have been better than optionals
in this case.

-- 
Raymond Wiker                        Mail:  ·············@fast.no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60

Try FAST Search: http://alltheweb.com/
From: Pascal Costanza
Subject: Re: How do I deal with &optional args?
Date: 
Message-ID: <c6em3i$di3$3@newsreader2.netcologne.de>
David Steuber wrote:

> Given this function:
> 
> (defun create-swank-server (&optional (port +server-port+)
>                             (background *communication-style*)
>                             (announce-fn #'simple-announce-function)
>                             dont-close)
>   (setup-server port announce-fn background dont-close))
> 
> I want to call create-swank-server with a specified port and
> dont-close.  In C++, I would be forced to also set background and
> announce-fn even though they have defaults because these are
> positional arguments.  Do I have to do the same in Lisp?

Yes. If you want to arbitrarily change the order of arguments, use 
keyword arguments. Just replace &optional with &key in your example, and 
then you can say this:

(create-swank-server :port 4005 :dont-close t)


Pascal

-- 
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
From: =?iso-8859-15?q?Pierre-Fran=E7ois_Gomez?=
Subject: SBCL + re-spawning, background swank server (was: How do I deal with &optional args?)
Date: 
Message-ID: <87d65w3yki.fsf@eithel.famille.local>
[ I'm still a CL newbie, first article here i think. I'll try my best not
to appear overconfident here and of course, all suggestions are accepted
:) ]

[ i meant to send this to c.l.l, not in private, sorry ]

David Steuber <·····@david-steuber.com> writes:

> I'm trying to setup SBCL so that I can connect and disconnect with
> SLIME at will and also have it talk to Apache when started with a
> shell script.

Hello David,

I think i read most of your articles/posts concerning this very topic,
either on c.l.l or on sbcl-devel (i can't remember where you started
writing about this :) ), and i felt very interested in setting up a long
running sbcl image on my box, too, but with swank and araneida.

After having read your articles and the detachtty page on the CLiki, i
started to work, and my gentoo box now has a new "service" called
long-running-sbcl which i can start and stop and attach at will, using
/etc/init.d/long-running-lisp <command>. It already starts a swank
server and i'm on the process of using araneida.

I'm using SBCL 0.8.9 with the last FAIRLY-STABLE slime cvs snapshot.

Back on your article, now : i think i've a couple of things to add to
what the others already said.

> Given this function:
>
> (defun create-swank-server (&optional (port +server-port+)
>                             (background *communication-style*)
>                             (announce-fn #'simple-announce-function)
>                             dont-close)
>   (setup-server port announce-fn background dont-close))
[...]
> don't really know if the right thing happened or not.  I want to start
> up SBCL with a shell script that has this in it:
>
> /usr/bin/detachtty --dribble-file /home/david/usr/var/run/lisp-dribble \
>                    --log-file /home/david/usr/var/run/detachtty.log \
>                    --pid-file /home/david/usr/var/run/lisp.pid \
>                    /home/david/usr/var/run/lisp-socket  \
>                    /home/david/usr/bin/sbcl \
>                      --eval '(asdf:operate 'asdf:load-op 'modlisp)' \
>                      --eval '(asdf:operate 'asdf:load-op 'cl-ppcre)' \
>                      --eval '(asdf:operate 'asdf:load-op 'lml2)' \
>                      --eval '(asdf:operate 'asdf:load-op 'swank)' \
>                      --eval '(ml:modlisp-start :port 3000)' \
> 		     --eval '(swank:create-swank-server 4005)'

In this last example, you obviously create a swank server that will
close its socket each time it loses its emacs connection.
As i understand your different posts, you seem to want swank both to be
started in the background and have its socket left open when it loses
its emacs connection.

Here's how i achieved that :
* (swank:create-swank-server 4005
                             :spawn
                             (lambda (port)
                               (format t "New swank server on port ~s~%" port))
                             t)
New swank server on port 4005
4005

A couple of notes here :
- in one of your previous attempts, i remember that you tried passing
  *communication-style* as the background argument, but it defaults to
  nil, in which case the swank server will close its socket when losing
  its emacs connection.
  Actually, anything but the :spawn symbol will make swank close its
  socket.
- i could have used #'simple-announce-function but since it is within the
  swank package, and not exported, i just thought it was easier that way :)
  Maybe i'm missing something here ?
- as expected, the swank server is started in the background and i can
  safely say '/etc/init.d/long-running-lisp attach' to get to the REPL
  (or i can simply use slime, i know :) ).

While testing this, i found that each time i closed the emacs connection
(using slime-disconnect), i also had to close and reopen emacs (21.3.1)
itself in order to be allowed to use slime-connect again.

Apart from this minor inconvenience, it works just fine for me.

-- 
Pierre-Fran�ois Gomez                                 GnuPG: 0xA38AE42C
From: David Steuber
Subject: Re: SBCL + re-spawning, background swank server (was: How do I deal with &optional args?)
Date: 
Message-ID: <87y8ojpzxm.fsf@david-steuber.com>
Pierre-François Gomez <·····················@NOSPAM-laposte.net> writes:

> [ i meant to send this to c.l.l, not in private, sorry ]

No problem.  I saw NOSPAM in your addy and thought I would check here
first before responding.

> David Steuber <·····@david-steuber.com> writes:
> 
> > I'm trying to setup SBCL so that I can connect and disconnect with
> > SLIME at will and also have it talk to Apache when started with a
> > shell script.
> 
> I think i read most of your articles/posts concerning this very topic,
> either on c.l.l or on sbcl-devel (i can't remember where you started
> writing about this :) ), and i felt very interested in setting up a long
> running sbcl image on my box, too, but with swank and araneida.
> 
> After having read your articles and the detachtty page on the CLiki, i
> started to work, and my gentoo box now has a new "service" called
> long-running-sbcl which i can start and stop and attach at will, using
> /etc/init.d/long-running-lisp <command>. It already starts a swank
> server and i'm on the process of using araneida.
> 
> I'm using SBCL 0.8.9 with the last FAIRLY-STABLE slime cvs snapshot.
> 
> Back on your article, now : i think i've a couple of things to add to
> what the others already said.
> 
> > Given this function:
> >
> > (defun create-swank-server (&optional (port +server-port+)
> >                             (background *communication-style*)
> >                             (announce-fn #'simple-announce-function)
> >                             dont-close)
> >   (setup-server port announce-fn background dont-close))
snip
> Here's how i achieved that :
> * (swank:create-swank-server 4005
>                              :spawn
>                              (lambda (port)
>                                (format t "New swank server on port ~s~%" port))
>                              t)

I actually sat down and tackled this problem last night and came up
with a fairly similar solution.  I don't have an /etc/init.d/ script
yet, but I do have a working launch script.

I'm surprised you didn't need #' with lambda.  I used a #'.

> A couple of notes here :
> - in one of your previous attempts, i remember that you tried passing
>   *communication-style* as the background argument, but it defaults to
>   nil, in which case the swank server will close its socket when losing
>   its emacs connection.
>   Actually, anything but the :spawn symbol will make swank close its
>   socket.

I wasn't aware that :spawn was so important.  I should probably change
the script I came up with (see URL below) except that it is working
exactly as I want.

> While testing this, i found that each time i closed the emacs connection
> (using slime-disconnect), i also had to close and reopen emacs (21.3.1)
> itself in order to be allowed to use slime-connect again.
> 
> Apart from this minor inconvenience, it works just fine for me.

I have not had that problem.  I can open and close the connection in
emacs at will (whatever version is in Debian/testing).

I "discovered" the macho-archives on common-lisp.net last night also
when I was doing a Google search to find Bill Clemontson's solution to
the problem.  He is on NT using ACL, so I needed something a bit
different.  Anyway, the macho-archives have the slime-devel mailing
list archived.  Last night, I posted my solution to slime-devel:

http://www.common-lisp.net/macho-archives/slime-devel/2004-4/1243.html

The complete text of my launch script is there.  It is currently
working as I like.  I didn't include the text of my sbclrc file which
is now just this:

$ cat usr/lib/sbcl/sbclrc 
(require :asdf)
(require :asdf-install)

I decided I didn't want my web application (which doesn't exist yet)
opening up with SBCL everytime, but I do want ASDF to be cocked,
locked, and ready to rock.

If create-swank-server is changed to use &keys instead of &optional,
my script will have to be changed.  I saw a mention from Helmut about
that possibility.  The main thing I was interested in was dont-close.
As for *communication-style*, I figured it was best to go with the
default and it is an exported symbol.  I keep upto date with SLIME for
the most part rather than using the FAIRLY-STABLE tag.

-- 
I wouldn't mind the rat race so much if it wasn't for all the damn cats.
From: Justin Dubs
Subject: Re: SBCL + re-spawning, background swank server (was: How do I deal with &optional args?)
Date: 
Message-ID: <2e262238.0404251755.37787e4f@posting.google.com>
David Steuber <·····@david-steuber.com> wrote in message news:<··············@david-steuber.com>...
>
> I'm surprised you didn't need #' with lambda.  I used a #'.
> 

You never /need/ sharp-quote with lambda.  See the definition of the
lambda macro in section 3.8 of the hyperspec:

"Provides a shorthand notation for a function special form involving a
lambda expression such that:

    (lambda lambda-list [[declaration* | documentation]] form*)
 ==  (function (lambda lambda-list [[declaration* | documentation]]
form*))
 ==  #'(lambda lambda-list [[declaration* | documentation]] form*)"

In other words, (lambda ...) expands to (function (lambda ...)).

Justin Dubs
From: David Steuber
Subject: Re: SBCL + re-spawning, background swank server (was: How do I deal with &optional args?)
Date: 
Message-ID: <87wu43e7wy.fsf@david-steuber.com>
······@eos.ncsu.edu (Justin Dubs) writes:

> David Steuber <·····@david-steuber.com> wrote in message news:<··············@david-steuber.com>...
> >
> > I'm surprised you didn't need #' with lambda.  I used a #'.
> > 
> 
> You never /need/ sharp-quote with lambda.  See the definition of the
> lambda macro in section 3.8 of the hyperspec:
> 
> "Provides a shorthand notation for a function special form involving a
> lambda expression such that:
> 
>     (lambda lambda-list [[declaration* | documentation]] form*)
>  ==  (function (lambda lambda-list [[declaration* | documentation]]
> form*))
>  ==  #'(lambda lambda-list [[declaration* | documentation]] form*)"
> 
> In other words, (lambda ...) expands to (function (lambda ...)).

I just had to run right out and try this.

; SLIME 2004-04-24
CL-USER> (mapcar (lambda (n) (* 2 n)) (list 1 2 3 4 5 6 7))
(2 4 6 8 10 12 14)
CL-USER> (mapcar #'(lambda (n) (* 2 n)) (list 1 2 3 4 5 6 7))
(2 4 6 8 10 12 14)

Well, it does the right thing.  I guess I learned something new.

BTW, I also just learned that M-x slime-connect works better from the
*scratch* buffer than from a GNUS buffer.  And just typing this caused
something odd to happen.  SBCL has gone to 100%.  Weird.  I called M-x
slime-disconnect.  Now I have to C-g for auto-fill to work.

I'll have to see if I have a bug here.

-- 
I wouldn't mind the rat race so much if it wasn't for all the damn cats.
From: David Steuber
Subject: Re: SBCL + re-spawning, background swank server (was: How do I deal with &optional args?)
Date: 
Message-ID: <878ygj1jq6.fsf@david-steuber.com>
David Steuber <·····@david-steuber.com> writes:

> BTW, I also just learned that M-x slime-connect works better from the
> *scratch* buffer than from a GNUS buffer.  And just typing this caused
> something odd to happen.  SBCL has gone to 100%.  Weird.  I called M-x
> slime-disconnect.  Now I have to C-g for auto-fill to work.
> 
> I'll have to see if I have a bug here.

I couldn't reproduce it.  That was weird.  Oh well.  Not only that,
but M-x slime-connect worked just fine from the Gnus Summary buffer.

I wonder what happened?

-- 
I wouldn't mind the rat race so much if it wasn't for all the damn cats.
From: Steven E. Harris
Subject: Re: SBCL + re-spawning, background swank server
Date: 
Message-ID: <q67d65uxkw4.fsf@L75001820.us.ray.com>
David Steuber <·····@david-steuber.com> writes:

> BTW, I also just learned that M-x slime-connect works better from
> the *scratch* buffer than from a GNUS buffer.

I find that slime-connect fails (or, rather, hangs) at least 50% of
the time with XEmacs and CLISP. There seems to be some kind of race
condition, perhaps with XEmacs trying to connect before the swank
server is ready to accept connections.

While typing this, I've been experimenting with starting a swank
server in shell outside of XEmacs (using swank:create-swank-server)
and connecting with an explicit `slime-connect', to no avail. The
server is out there listening, but XEmacs never gets the connection
right. It either just hangs or the server rejects the connection.

-- 
Steven E. Harris        :: ········@raytheon.com
Raytheon                :: http://www.raytheon.com
From: Steven E. Harris
Subject: Re: SBCL + re-spawning, background swank server
Date: 
Message-ID: <q678ygixjjc.fsf@L75001820.us.ray.com>
"Steven E. Harris" <········@raytheon.com> writes:

> The server is out there listening, but XEmacs never gets the
> connection right. It either just hangs or the server rejects the
> connection.

After more trial and error, I did get this to work. The /first/ slime
connection is unreliable, though. Usually it fails one or two times
before finally connecting properly.

-- 
Steven E. Harris        :: ········@raytheon.com
Raytheon                :: http://www.raytheon.com
From: ·········@random-state.net
Subject: Re: SBCL + re-spawning, background swank server
Date: 
Message-ID: <c6l8gu$8g271$1@midnight.cs.hut.fi>
Steven E. Harris <········@raytheon.com> wrote:

> I find that slime-connect fails (or, rather, hangs) at least 50% of
> the time with XEmacs and CLISP. There seems to be some kind of race

Reporting on slime-devel is probably a good idea -- the folks
there are pretty responsive.

Cheers,

 -- Nikodemus
From: =?iso-8859-15?q?Pierre-Fran=E7ois_Gomez?=
Subject: Re: SBCL + re-spawning, background swank server
Date: 
Message-ID: <87ad0yvqhe.fsf@eithel.famille.local>
David Steuber <·····@david-steuber.com> writes:

> I'm surprised you didn't need #' with lambda.  I used a #'.

I'm surprised, too : this escaped my notice. Thanks to Justin Dubs, we
now have an explanation for this, and i learned something in the process
: so nice to be a newbie :)

>> While testing this, i found that each time i closed the emacs
>> connection (using slime-disconnect), i also had to close and reopen
>> emacs (21.3.1) itself in order to be allowed to use slime-connect
>> again.
>> 
>> Apart from this minor inconvenience, it works just fine for me.
>
> I have not had that problem.  I can open and close the connection in
> emacs at will (whatever version is in Debian/testing).

Oh ? This may come from my build, then. I'll try with an Emacs i
compiled myself, not gentoo's one. Maybe trying the HEAD cvs tag of
slime would help, too (well, first). Thanks for your feedback.

It's not a big problem for me, though : i can't think of a situation
were i would disconnect slime without closing Emacs as well :)

> list archived.  Last night, I posted my solution to slime-devel:

I borrowed your using of (...asdf:load-op :swank) from your solution. I
was just require'ing it.

> default and it is an exported symbol.  I keep upto date with SLIME for
> the most part rather than using the FAIRLY-STABLE tag.

I think i'll stick with FAIRLY-STABLE for now : it's should avoid me
some of the nastiest bugs and... it's fairly stable :)

Regards,
-- 
Pierre-Fran�ois Gomez                                 GnuPG: 0xA38AE42C
From: David Steuber
Subject: Re: SBCL + re-spawning, background swank server
Date: 
Message-ID: <87smeqi9pm.fsf@david-steuber.com>
Pierre-François Gomez <·····················@NOSPAM-laposte.net> writes:

> I borrowed your using of (...asdf:load-op :swank) from your solution. I
> was just require'ing it.

For some reason (perhaps I was doing something wrong), require wasn't
working for me, hence the asdf incantation.

-- 
I wouldn't mind the rat race so much if it wasn't for all the damn cats.