tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

I'm playing with common lisp using lispbox SLIME. Pretty cool to learn on.

But everything happens in the SLIME emacs top level.

Maybe this is wishful thinking, but I would like to be able to be able to get lisp playing with my bash shell. I would like to get lisp playing... with perl.

Is there some way for perl to talk to SLIME? To any kind of emacs? To any kind of lisp? Or, for the previous three questions, s/perl/bash/... which, I guess amounts to the same thing, given backticks.....

Can someone make the following code work?

use strict; use warnings; #perl hello world print 'perl hello world'; #lisp hello world; my $lisp_hello_world = '\'(lisp hello world)'; run_lisp($lisp_hello_world); # should print LISP HELLO WORLD # the same as SLIME #can someone make this work? sub run_lisp { }

Replies are listed 'Best First'.
Re: Is there a way to call lisp from perl?
by salva (Canon) on Mar 20, 2006 at 11:27 UTC
    have you tried Guile?

    Anyway, usually there are three ways to run code in another language inside Perl:

    • writing an interpreter in Perl: it's a lot of work, and probably going to be very slow but on the other hand you get maximum portability and good integration with Perl.
    • running an interpreter (or on the fly compile and run) for the other language and using sockets to communicate with it. It's probably faster than the previous solution although all the data crossing the interface has to be serialized and that can be expensive. Also, you have to take into account special situations like exceptions crossing the interface, sometimes, getting both languages in sync could be difficult.
    • finally, if the interpreter for the other language exists as a library, you can write an XS wrapper. Difficulty varies depending on the language and how well designed the library API is, and obviously, you need too know a bit about XS. Then there are complex matters as threads or sharing file descriptors between both languages that can get really tricky.

    update: well, I was thinking about languages interpreted or that run on a virtual machine. For languages compiled to run in real processors, the usual way to interface with them is to use some kind of code generator (XS, SWIG or Inline::C for instance).

Re: Is there a way to call lisp from perl?
by diotalevi (Canon) on Mar 20, 2006 at 14:17 UTC

    Adding onto the other note, SLIME doesn't actually run the lisp in emacs. It runs your Common Lisp interpreter as a separate process to emacs, it's an inferior mode. When you evaluate something, emacs sends that expression over to the clisp shell and hits enter for you. The results are interpreted by emacs. There's no magic here - Emacs hasn't suddenly become clisp, it just has a spiffy interface. shell-mode and various sql-modes work like this too.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: Is there a way to call lisp from perl?
by Fletch (Bishop) on Mar 20, 2006 at 14:58 UTC

    Not exactly what you want (geared at letting you write functions for Emacs in Perl rather than elisp), but Emacs::EPL might be of interest.

Re: Is there a way to call lisp from perl?
by samizdat (Vicar) on Mar 20, 2006 at 20:04 UTC
    Look at the Arrow LISP source code... here. It's a simple pure-symbolic variant, but there is also freeware out there for Common Lisp subsets and full implementations. Here is a list of all LISP tools available on FreeBSD. Most should also be available on Linux et al, see this site for more links. As others have said, wrap one of them in SWIG or XS.

    Don Wilde
    "There's more than one level to any answer."
Re: Is there a way to call lisp from perl?
by Anonymous Monk on Mar 20, 2006 at 15:20 UTC
    You could fake it with something as simple as this, if you're not doing anything too complex on the LISP side...
    sub run_lisp { my ($lisp_code) = @_; my $lisp_result; $lisp_result = `lisp_interpreter $lisp_code`; return($lisp_result); }
Re: Is there a way to call lisp from perl?
by aufflick (Deacon) on Mar 21, 2006 at 13:18 UTC
    I was surprised that Inline:: didn't support lisp. The author would presumably be surprised also:

    Projects that I would most like to see happen in the year 2001 are:
    - Fortran
    - Ruby
    - Lisp
    - Guile
    - Bash
    - Perl4
    Of course if the documentation was up to date it should include something like:

    Projects that I would most like to see happen in the year 2006 are:
    - Perl6
    ;)

        Except that Inline::Guile doesn't actually work. I've no idea about Inline::MzScheme.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊