From: ·····@apc.happyleptic.org
Subject: Several REPL attached to a single image
Date: 
Message-ID: <slrnfk7rms.h17.rixed@apc.happyleptic.org>
Hello world!
Im just curious about Lisp, not even an occasional user.

Anyway, Im looking for somehting that's perhaps obvious, perhaps
stupid : I would like to have a lisp running somewhere and "connect"
to it with several REPL. I've looked various (free) lisp implementations
without finding anything close, so I don't know if it's feasable.

Actually, I am not even sure it would be usefull, but I feel I need
it :-) - may be usefull for client-server apps, for teaching - editing
the same "program" with multiple hands, etc...

I've looked at swank but apparently having it answer to several slime
clients is undocumented.

What do you think ?

(Note: if this rely on some particular implementation magic, Im using
clisp or gcl or ecl, which are not the biggest, but because of that I
managed to port them on my ARM "server", while neither sbcl, cmucl nor
openmcl are portable)

Many thanks in advance for any pointer.

From: Rob Warnock
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <s92dnQNzVojck9nanZ2dnUVZ_t2inZ2d@speakeasy.net>
<·····@apc.happyleptic.org> wrote:
+---------------
| I would like to have a lisp running somewhere and "connect"
| to it with several REPL. I've looked various (free) lisp implementations
| without finding anything close, so I don't know if it's feasable.
...
| (Note: if this rely on some particular implementation magic, Im using
| clisp or gcl or ecl, which are not the biggest, but because of that I
| managed to port them on my ARM "server", while neither sbcl, cmucl nor
| openmcl are portable)
+---------------

I'm sorry CMUCL isn't acceptable to you, since it comes with a built-in
function that does exactly what you want:

    cmu> (describe 'mp::start-lisp-connection-listener)
    START-LISP-CONNECTION-LISTENER is an internal symbol in the MULTIPROCESSING package.
    Function: #<Function MULTIPROCESSING::START-LISP-CONNECTION-LISTENER {10331281}>
    Function arguments:
      (&key (port 1025) (password (random (expt 2 24))))
    Function documentation:
      Create a Lisp connection listener, listening on a TCP port for new
      connections and starting a new top-level loop for each. If a password
      is not given then one will be generated and reported.  A search is
      performed for the first free port starting at the given port which
      defaults to 1025.
    Its defined argument types are:
      (&KEY (:PORT (UNSIGNED-BYTE 16)) (:PASSWORD T))
    Its result type is:
      T
    On Wednesday, 11/16/05 05:14:48 pm PST it was compiled from:
    target:code/multi-proc.lisp
      Created: Tuesday, 7/5/05 06:12:50 am PDT
      Comment: $Header: /project/cmucl/cvsroot/src/code/multi-proc.lisp,v 1.43 2005/07/05 13:12:50 rtoy Exp $
    cmu> 

You use it like this:

    cmu> (mp::start-lisp-connection-listener)

    #<Process Anonymous {4894FE5D}>
    cmu> 
    ;;; Started lisp connection listener on port 1025 with password 6600875

Then from anywhere in the world, you just Telnet to there, type the
password, and you're in a REPL, e.g.:

    $ telnet my-host-name 1025
    Trying [my-IP-address]...
    Connected to my-host-name.
    Escape character is '^]'.
    Enter password: 6600875       <== I typed the password

    cmu> (mp:all-processes)

    (#<Process Lisp session from [client-host-name] {48952B75}>
     #<Process Lisp connection listener on port 1025 {4894FE5D}>
     #<Process Initial {48008005}>)
    cmu> 

Note: The password is any readable CL *object*, so you can certainly
make *much* stronger password than a weak random 24-bit number
[a much longer string or symbol, for instance].

Note#2: Things are arranged so that if you call (QUIT) from one
of the remote REPL sessions, you kill *only* that session, not
the whole CMUCL image.

In any case, you might look for something similar in one of the
implementations you find acceptable, or if nothing exists already,
you could implement the above function signature yourself from
whatever network socket and thread primitives your implementation
does provide.

In case it helps, the source for CMUCL's START-LISP-CONNECTION-LISTENER
is ~90 lines of code, down near the bottom of this file:

    http://common-lisp.net/cgi-bin/viewcvs.cgi/*checkout*/src/code/multi-proc.lisp?root=cmucl

You'll also need a sample top-level REPL to call; the one CMUCL's
START-LISP-CONNECTION-LISTENER uses is called TOP-LEVEL, is ~30 lines
of code, and is in the same file just a little bit farther up.


-Rob

p.s. CMUCL *is* "portable" -- it runs on multiple platforms [albeit
fewer than in times past], and it had to be "ported" for that to happen.
But I agree that you need to be a fairly-competent compiler writer to
port CMUCL to a new architecture. It's certainly not as easy as just
recompiling a C program.

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: ·····@apc.happyleptic.org
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <slrnfk8pr5.l2c.rixed@apc.happyleptic.org>
> I'm sorry CMUCL isn't acceptable to you, since it comes with a built-in
> function that does exactly what you want:

Now that I think about it, the lisp implementation has to(*) support
multi threading to allow this (data protection is required between
the several REPL), and neither gcl, ecl nor clisp support it (AFAIK).

(*)Somthing that will just eval forms atomically would be enought for
me, but for any serious usage multi-threading is a must-have.

> p.s. CMUCL *is* "portable" -- it runs on multiple platforms [albeit
> fewer than in times past], and it had to be "ported" for that to happen.

Sory for my misuse of english : cmucl is certainly portable, and I did
not *port* any of the lisp the works for my ARM - I merely compiled them
(well, had to work a little harder for clisp though).

I certainly won't port cmucl on ARM - even if I were familiar enough
with lisp and cmucl, I don't have enough time for this. I would be
glad someone do it, anyway (for a next google summer of code maybe ?)
:-)
From: Juanjo
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <81034df0-4f4d-408d-9253-a02571bb6d25@d61g2000hsa.googlegroups.com>
On Nov 21, 5:42 pm, ·····@apc.happyleptic.org wrote:
> Now that I think about it, the lisp implementation has to(*) support
> multi threading to allow this (data protection is required between
> the several REPL), and neither gcl,eclnor clisp support it (AFAIK).

Check ECL again. It has and uses native threads, and thread-local
global variables. The problem seems to be that the manual page
documenting it, which was in the old wiki, has been trashed. But the
interface is very similar to OpenMCL's and other's. It is also a bit
more polished in the CVS version.

Juanjo
From: Juanjo
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <cd362a12-a26b-4634-85c7-4756a4f09a21@s12g2000prg.googlegroups.com>
On Nov 24, 10:38 am, Juanjo <·····················@googlemail.com>
wrote:
> On Nov 21, 5:42 pm, ·····@apc.happyleptic.org wrote:
>
> > Now that I think about it, the lisp implementation has to(*) support
> > multi threading to allow this (data protection is required between
> > the several REPL), and neither gcl,eclnor clisp support it (AFAIK).
>
> Check ECL again. It has and uses native threads, and thread-local
> global variables. The problem seems to be that the manual page
> documenting it, which was in the old wiki, has been trashed. But the
> interface is very similar to OpenMCL's and other's. It is also a bit
> more polished in the CVS version.
>
> Juanjo

Just in case you want to try it, here is a sketch of the future
manual:
http://ecls.sourceforge.net/new-manual/ch18.html

To get support for native threads, you have to configure ECL using the
flag --enable-threads.

Juanjo
From: ·····@apc.happyleptic.org
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <slrnfkl48m.adu.rixed@apc.happyleptic.org>
Thank you very much.
I should be able to do what I looked for with this and a small amount of
programming.
From: Tobias C. Rittweiler
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <87myt8ui3l.fsf@freebits.de>
·····@apc.happyleptic.org writes:

> I've looked at swank but apparently having it answer to several slime
> clients is undocumented.

You probably want to load the SWANK server with SWANK:*DONT-CLOSE* being
T. From Slime, you can use `slime-connect' to connect to as many swank
server as you want. (And, in fact, if you do `M-x slime' twice, the
second time you're asked if it should restart the current connection, or
create a new one.)

  -T.
From: Petter Gustad
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <873auzu6pn.fsf@gustad.com>
"Tobias C. Rittweiler" <···@freebits.de.invalid> writes:

> ·····@apc.happyleptic.org writes:
> 
> > I've looked at swank but apparently having it answer to several slime
> > clients is undocumented.
> 
> You probably want to load the SWANK server with SWANK:*DONT-CLOSE* being
> T. From Slime, you can use `slime-connect' to connect to as many swank

I got the impression that he wanted to do the opposite. Connect to a
swank server from multiple locations. You can do this by issuing a 

(asdf:operate 'asdf:load-op :swank) ;; the first time or from the top asd
(swank:create-swank-server 4005)

in the repl. I have my lisp running under screen so I can just connect
to it an issue the above at any time. At bootup a crontab job runs
something like:

screen -D -m -S aserve /usr/bin/lisp \
        -eval "(asdf:operate 'asdf:load-op :web)" \
        -eval "(mp:make-process #'web:start-web-server)" \
        -eval '(mp::startup-idle-and-top-level-loops)'

I can then login into the server with ssh and do a "screen -r aserve"
to get into the repl and start a swank server.

Petter

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: ·····@apc.happyleptic.org
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <slrnfk8q6k.l2c.rixed@apc.happyleptic.org>
On 2007-11-21, Petter Gustad <·············@gustad.com> wrote:
> "Tobias C. Rittweiler" <···@freebits.de.invalid> writes:
>
> I got the impression that he wanted to do the opposite. Connect to a
> swank server from multiple locations. You can do this by issuing a 

Probably because I misinterpreted what swank is all about. For me,
being connected from several places to the same cmucl, as in the
example above, or to the same swank server, is the same thing : you
can give orders from several places to the same lisp image. So that
in one REPL you type "(defparameter *thing* 'thong)" and in the other
*thing* became bound to 'thong.

Yes I know you can "simulate" this by sharing a terminal with screen,
but this is not at all as convenient.
From: Tobias C. Rittweiler
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <87tznfh3zu.fsf@freebits.de>
Petter Gustad <·············@gustad.com> writes:

> "Tobias C. Rittweiler" <···@freebits.de.invalid> writes:
>
> > ·····@apc.happyleptic.org writes:
> > 
> > > I've looked at swank but apparently having it answer to several slime
> > > clients is undocumented.
> > 
> > You probably want to load the SWANK server with SWANK:*DONT-CLOSE* being
> > T. From Slime, you can use `slime-connect' to connect to as many swank
>
> I got the impression that he wanted to do the opposite. Connect to a
> swank server from multiple locations. 

This case is exactly what my post described how to accomplish
properly. (Perhaps, with the additional note that you can of course use
`slime-connect' from multiple Slime instances.)

Also I'd like to note at this point that if you really want to do this
remotely, you'll most likely want this to take place through SSH.

  -T.
From: Petter Gustad
Subject: Re: Several REPL attached to a single image
Date: 
Message-ID: <87lk8qegef.fsf@gustad.com>
"Tobias C. Rittweiler" <···@freebits.de.invalid> writes:

> This case is exactly what my post described how to accomplish

Yes it did. I was was just confused by the multiple servers issue.
Sorry.

Petter
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?