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.
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
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
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.
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
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
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
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. :|
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
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