From: cartercc
Subject: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <0b8afab0-7f2d-4ddc-8f97-23e5ba669a1b@z18g2000prn.googlegroups.com>
This is a kind of a follow up to my previous post about executable
form of a Lisp program.

When I write a Perl script and include "#! /usr/bin/perl" as the first
line, I can chmod it to 755 and run it like "perl ./script.plx".

Can I do the same with a Lisp script? If so, is there any kind of
documentation on it?

Thanks, CC.

From: blandest
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <8d945926-25d8-4ad9-b20b-a61c79ae7e07@u29g2000pro.googlegroups.com>
On Oct 10, 3:35 pm, cartercc <········@gmail.com> wrote:
> This is a kind of a follow up to my previous post about executable
> form of a Lisp program.
>
> When I write a Perl script and include "#! /usr/bin/perl" as the first
> line, I can chmod it to 755 and run it like "perl ./script.plx".
>
> Can I do the same with a Lisp script? If so, is there any kind of
> documentation on it?
>
> Thanks, CC.

I don't think that this is standard, but it works in clisp:

------ test.lisp ------
#!/usr/bin/clisp

(print 'ok)
-----------------------

$./test.lisp

OK
From: Nicolas Edel
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <ff5c4d78-c094-408f-a37b-7b1f9668dc7a@q26g2000prq.googlegroups.com>
On Oct 10, 3:05 pm, blandest <··············@gmail.com> wrote:
> On Oct 10, 3:35 pm, cartercc <········@gmail.com> wrote:
>
> > This is a kind of a follow up to my previous post about executable
> > form of a Lisp program.
>
> > When I write a Perl script and include "#! /usr/bin/perl" as the first
> > line, I can chmod it to 755 and run it like "perl ./script.plx".
>
> > Can I do the same with a Lisp script? If so, is there any kind of
> > documentation on it?
>
> > Thanks, CC.
>
> I don't think that this is standard, but it works in clisp:
>

It is not.
It's built-in in clisp.
There are some tricks to do it with sbcl (1), thus requiring .sbclrc
customization. Or just use it as described in section Scripts of
http://www.cliki.net/SBCL


-Nicolas


(1) http://www.sbcl.org/manual/Unix_002dstyle-Command-Line-Protocol.html#Unix_002dstyle-Command-Line-Protocol
From: Alex Mizrahi
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <48ef6448$0$90266$14726298@news.sunsite.dk>
 c> When I write a Perl script and include "#! /usr/bin/perl" as the first
 c> line, I can chmod it to 755 and run it like "perl ./script.plx".

it looks like you're a bit confused. it makes sense _either_ to
chmod it to 755 and run it as

  ./script.plx

OR run it with mere

  perl script.plx

in later case you do not need to make it executable (you can, of course, but 
that won't make any difference).

 c> Can I do the same with a Lisp script?

most implementations allow to load program via command line parameters, 
e.g.:

  sbcl --load my.lisp
  clisp my.lisp

consult your implementation manual.

yep, but making it directly executable is considered to be a hack. i suggest 
you
using two files instead, e.g. to run your myutil.lisp file you create a 
shell script myutil
with aprox such contents:

---------
#!/bin/sh

sbcl -- load "myutil.lisp"
---------

and chmod it. it is a flexible solution -- this way you can load 
dependencies
from via asdf etc. 
From: cartercc
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <6e050840-3ed1-425c-b488-39f74d1a6a7a@s50g2000hsb.googlegroups.com>
On Oct 10, 9:18 am, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:

> it looks like you're a bit confused. it makes sense _either_ to
> chmod it to 755 and run it as
>
>   ./script.plx
>
> OR run it with mere
>
>   perl script.plx

Yes, you are correct. It runs as "perl script.plx" or as "./
script.plx". Sorry for the confusion.

> most implementations allow to load program via command line parameters,
> e.g.:
>
>   sbcl --load my.lisp
>   clisp my.lisp
>
> consult your implementation manual.

Am using CMUCL on Linux.

> using two files instead, e.g. to run your myutil.lisp file you create a
> shell script myutil
> with aprox such contents:
>
> ---------
> #!/bin/sh
>
> sbcl -- load "myutil.lisp"
> ---------
>
> and chmod it. it is a flexible solution -- this way you can load
> dependencies
> from via asdf etc.

Good idea! I'll try it.

CC
From: Tim X
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <878wsvq42j.fsf@lion.rapttech.com.au>
cartercc <········@gmail.com> writes:

> On Oct 10, 9:18 am, "Alex Mizrahi" <········@users.sourceforge.net>
> wrote:
>
>> it looks like you're a bit confused. it makes sense _either_ to
>> chmod it to 755 and run it as
>>
>>   ./script.plx
>>
>> OR run it with mere
>>
>>   perl script.plx
>
> Yes, you are correct. It runs as "perl script.plx" or as "./
> script.plx". Sorry for the confusion.
>
>> most implementations allow to load program via command line parameters,
>> e.g.:
>>
>>   sbcl --load my.lisp
>>   clisp my.lisp
>>
>> consult your implementation manual.
>
> Am using CMUCL on Linux.
>
>> using two files instead, e.g. to run your myutil.lisp file you create a
>> shell script myutil
>> with aprox such contents:
>>
>> ---------
>> #!/bin/sh
>>
>> sbcl -- load "myutil.lisp"
>> ---------
>>
>> and chmod it. it is a flexible solution -- this way you can load
>> dependencies
>> from via asdf etc.
>
> Good idea! I'll try it.
>
> CC

Another alternative that may work since your on Linux is to use the misc
binary format kernel module. I've not looked at this module for a while,
but it does allow you to set things up so that just calling the file
will execute it. For example, some years ago, I had a setup where you
could do 

./myprog.java

and it would execute the program in myprog.java by calling the jre you
had configured. It shouldn't be too difficult to just do the same for
lisp. Of course, this does make it platform specific.

You may also want to check the archives of this group. Rob Warnock has
posted some code that he uses that provides functionality that can be
quite useful if you want to have an environment where you use lisp for
'scripting' type tasks. 

Personally, when I want lisp like facilities in a scripting type of
environment, I tend to use rep, guile or lush. 

Tim

-- 
tcross (at) rapttech dot com dot au
From: Nikodemus Siivola
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <f9a65603-c387-4bc7-bc22-504b71167869@k37g2000hsf.googlegroups.com>
As of SBCL 1.0.12.17, shebang-style scripts are supported out of the
box:

$ cat > hello
#!/usr/local/bin/sbcl --script
(format t "Hello ~A!~%" (or (second *posix-argv*) "World"))
^D
$ chmod a+x hello
$ ./hello
Hello World!
$ ./hello you
Hello you!

Cheers,

 -- Nikodemus
From: Nikodemus Siivola
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <1d4ec08a-2159-4606-a5d3-e77c0b0ea907@q9g2000hsb.googlegroups.com>
On Oct 11, 4:39 pm, Nikodemus Siivola <·········@random-state.net>
wrote:
> As of SBCL 1.0.12.17, shebang-style scripts are supported out of the
                 ^^
Sorry, typo: should have been 1.0.21.17.

 -- Nikodemus
From: Paul Donnelly
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <87ej2lk6he.fsf@plap.localdomain>
Nikodemus Siivola <·········@random-state.net> writes:

> On Oct 11, 4:39 pm, Nikodemus Siivola <·········@random-state.net>
> wrote:
>> As of SBCL 1.0.12.17, shebang-style scripts are supported out of the
>                  ^^
> Sorry, typo: should have been 1.0.21.17.
>
>  -- Nikodemus

Well, that explains why it didn't work in 1.0.18. :|
From: Rob Warnock
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <5PSdnWxIW8Xdm23VnZ2dnUVZ_vudnZ2d@speakeasy.net>
cartercc  <········@gmail.com> wrote:
+---------------
| When I write a Perl script and include "#! /usr/bin/perl" as the first
| line, I can chmod it to 755 and run it like "perl ./script.plx".
+---------------

As others have noted, you probably meant "run it with ``./script.plx''".

+---------------
| Can I do the same with a Lisp script?
+---------------

As others have noted, this is not a part of the ANSI Common Lisp
standard, but various implementations [CLISP & SBCL were already
discussed] or their users have provided ways to accomplish it,
since it's *so* useful!

For CMUCL, here's my favorite way [for reasons that should be obvious]:

1. Download the following small hack and install per the instructions given
   within [includes a 3-line tweak to your "library:site-init.lisp" file]:

      http://rpw3.org/hacks/lisp/site-switch-script.lisp

2. If you've installed CMUCL as "lisp" start your scripts with
   "#!/usr/local/bin/lisp -script", or, if as "cmucl" (as I personally
   prefer) then use "#!/usr/local/bin/cmucl -script".

3. Example:

      $ which cmucl
      /usr/local/bin/cmucl
      $ ls -l hello
      -rwxr-xr-x  1 rpw3  rpw3     172 Nov 24  2007 hello
      $ cat hello
      #!/usr/local/bin/cmucl -script
      (format t "Hello, world!~%")
      (loop for arg in (cons *script-name* *script-args*)
	    and i from 0
	do (format t "argv[~a] = ~s~%" i arg))
      $ ./hello -opt1 foo bar
      Hello, world!
      argv[0] = "./hello"
      argv[1] = "-opt1"
      argv[2] = "foo"
      argv[3] = "bar"
      $ 

Other ways to do it with CMUCL:

    http://www.cliki.net/CMUCL%20Hints
    ...
    Running Lisp programs from the shell prompt
    ...[method#1]...
    
    (also see [this page])
	      http://users.actrix.co.nz/mycroft/runlisp.html

    CMUCL shell scripts
    ...[methods #3, #4, #5, etc.]...

Still more general methods:

    http://www.cliki.net/ShellScripting

    http://www.cliki.net/cl-launch

    http://www.cliki.net/Creating%20Executables


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: cartercc
Subject: Re: #! /usr/local/bin/lisp ?
Date: 
Message-ID: <e847fcf3-6dad-4d96-8f0b-bf2e62458ce4@p49g2000hsd.googlegroups.com>
Thanks. I've got a ways to go yet before I can write something that
will actually perform a useful task, but when I get there (and I
will!) I may have to ask for some technical help.

CC

On Oct 10, 9:49 pm, ····@rpw3.org (Rob Warnock) wrote:
> For CMUCL, here's my favorite way [for reasons that should be obvious]:
>
> 1. Download the following small hack and install per the instructions given
>    within [includes a 3-line tweak to your "library:site-init.lisp" file]:
>
>      http://rpw3.org/hacks/lisp/site-switch-script.lisp
>
> 2. If you've installed CMUCL as "lisp" start your scripts with
>    "#!/usr/local/bin/lisp -script", or, if as "cmucl" (as I personally
>    prefer) then use "#!/usr/local/bin/cmucl -script".
>
> 3. Example:
>
>       $ which cmucl
>       /usr/local/bin/cmucl
>       $ ls -l hello
>       -rwxr-xr-x  1 rpw3  rpw3     172 Nov 24  2007 hello
>       $ cat hello
>       #!/usr/local/bin/cmucl -script
>       (format t "Hello, world!~%")
>       (loop for arg in (cons *script-name* *script-args*)
>             and i from 0
>         do (format t "argv[~a] = ~s~%" i arg))
>       $ ./hello -opt1 foo bar
>       Hello, world!
>       argv[0] = "./hello"
>       argv[1] = "-opt1"
>       argv[2] = "foo"
>       argv[3] = "bar"
>       $
>
> Other ways to do it with CMUCL:
>
>    http://www.cliki.net/CMUCL%20Hints
>     ...
>     Running Lisp programs from the shell prompt
>     ...[method#1]...
>
>     (also see [this page])
>              http://users.actrix.co.nz/mycroft/runlisp.html
>
>     CMUCL shell scripts
>     ...[methods #3, #4, #5, etc.]...
>
> Still more general methods:
>
>    http://www.cliki.net/ShellScripting
>
>    http://www.cliki.net/cl-launch
>
>    http://www.cliki.net/Creating%20Executables
>
> -Rob
>
> -----
> Rob Warnock                     <····@rpw3.org>
> 627 26th Avenue                 <URL:http://rpw3.org/>
> San Mateo, CA 94403             (650)572-2607