Subject: [clisp-list] arguments to a saved image? 3 suggestions.

From: Pascal Bourguignon <[email-masked]>
Date: Sun Mar 16 23:54:21 2003

When  invoking  clisp   as  an  interpreter,  (#!/usr/bin/clisp),  the
argument given to the script are passed via ext:*args*.

But in that case, when we load a saved image like in

#!/usr/bin/clisp -M image.mem

the init-function is not called.

On the other hand, if it's called as:

#!/bin/sh
/usr/bin/clisp -M image.mem

there is no way to pass the arguments.

Notably, 

#!/bin/sh
/usr/bin/clisp -M image.mem -x "(setq ext:*args* '($@))"

does not work because -x just executes one form then exits!

How one can pass arguments to a saved image with a init-function?

Another problem  with -x is that  it parses the  form before executing
it, so it is not possible to do on the command line something like:

    clisp -x '(progn (defpackage "TEST") (defun test::f ())'

*** - READ from #<INPUT STRING-INPUT-STREAM>: there is no package with name "TEST"

I would suggest to have clisp behave like emacs with respect to the -x
option:

    - several -x options must be allowed,

    - clisp should not exit automatically after a -x form is processed.

    - each form processed by a  -x option would be executed before the
      next -x is processed (like if  each form was on a different line
      in a script or interactively).

    - all the  -x options should be  run after loading  the image, but
      before  running the init-function.   Well, this  point is  to be
      studied.   If we consider  the init-function  as a  "main" entry
      point into the  program saved in the image, then  we want the -x
      forms  be run  before because  the init-function  would  run the
      program and then exit.  On  the other hand, if the init-function
      is merely an initialization function  and then return to the top
      level loop,  we may want  to be able  to run the -x  forms after
      this  initialization.   

So I  would suggest to  add a main-function parameter  to saveinitmem.
Then the -x forms could be executed after the init-function but before
the  main-function,   and  clisp  could  quit   automatically  when  a
main-function is given after running it.

So:

    clisp -x '(defpackage "TEST")' -x '(defun test::f ())'

would be legal and would work as expected.    

Finally, I would  suggest to have a mean to pass  arguments to a clisp
programs when clisp is not invoked  as an interpreter. Well, if the -x
suggestions above are implemented, one could write:
   
    clisp -K yyy  -M xxx.mem -x ... -x ... -x "(setq ext:*args* '( $@ ))"

but it may be cleaner to have an option to do that, for example:

    clisp -K yyy  -M xxx.mem -x ... -x ... -- $@

In that case we would get  the same processing of the arguments put in
ext:*args* in  all cases, [ -x  "(setq ext:*args* '( $@  ))" would put
symbols and numbers  in ext:*args* unless the script  processes $@ and
put double-quotes arround them].

-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.

---

From: Sam Steingold <[email-masked]>
Date: Mon Mar 17 07:01:39 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] arguments to a saved image?  3 suggestions."
> * Sent on Mon, 17 Mar 2003 08:53:53 +0100 (CET)
> * Honorable Pascal Bourguignon <[email-masked]> writes:
>

indeed.
<http://clisp.cons.org/clisp.html#opt-exec-file>

> the init-function is not called.

indeed.  this is so that you can re-use the image for scripting as well
as interactive purposes.
if you want to call the init-function, you can do

===================================
#!/usr/bin/clisp -M image.mem
(init-function)
...
===================================

> there is no way to pass the arguments.

===================================
#!/bin/sh
/usr/bin/clisp -M image.mem $@
===================================

> does not work because -x just executes one form then exits!

indeed, as documented
<http://clisp.cons.org/clisp.html#opt-exec-expr>

> How one can pass arguments to a saved image with a init-function?

<http://clisp.cons.org/clisp.html#opt-exec-expr>

$ clisp -M image.mem "" my-arg1 my-arg2 my-arg3

> *** - READ from #<INPUT STRING-INPUT-STREAM>: there is no package with name "TEST"

try

clisp -x '(defpackage "TEST") (defun test::f ())'

>     - several -x options must be allowed,

clisp -x "(foo)" -x "(bar)" === clisp -x "(foobar)"

what do we need the sugar for?

>     - clisp should not exit automatically after a -x form is processed.

this is an incompatible change of dubious value.
if you want -x, you are probably in a script or makefile and will have
to add (exit) as the last form.
if you want REPL, you can either start with your forms or put them into
init-function of your memory image.

>       in a script or interactively).

this is already done with multiple forms as -x argument

>       level loop, we may want to be able to run the -x forms after

init-function is for initialization.
e.g., this is the right place to reset the -encoding* places if you do
not want to set your environment properly.
<http://clisp.cons.org/clisp.html#opt-enc>
you don't want to run anything before it.

> Do not adjust your mind, there is a fault in reality.

Please do adjust your mind as documented above and update your
proposals accordingly.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
When you talk to God, it's prayer; when He talks to you, it's schizophrenia.

---

From: Pascal Bourguignon <[email-masked]>
Date: Mon Mar 17 21:14:02 2003

> <http://clisp.cons.org/clisp.html#opt-exec-expr>

So I was wrong here, -x executes several forms (-x expressionS) .
 
> $ clisp -M image.mem "" my-arg1 my-arg2 my-arg3

Any  reason in  particular why  it does  not use  the standard  (or at
least, the classical) -- argument separator?

You don't  expect us  to read the  whole documentation, do  you?  I've
searched for  '--' in the  manual page and  since I've not found  it I
concluded erroneously that the feature was not there.

> clisp -x '(defpackage "TEST") (defun test::f ())'

Yes, it  works.  Thank  you.  I  must confess that  I infered  that it
expected only one form from  my previous experience with emacs. Sorry.
But since the  ability to process several forms  is already there, why
not allowing several -x options too?

> clisp -x "(foo)" -x "(bar)" === clisp -x "(foobar)"

Or perhaps:  clisp -x "(foo) (bar)"

> what do we need the sugar for?

Convenience.   To  match expectation  from  people  having used  other
similar programs.

> to add (exit) as the last form.

Once again, at  least one pre-existing lisp (emacs)  does it the other
way.  Why  would  you  want  to  be incompatible  with  it  and  break
expectations?

> Please do adjust your mind as documented above and update your

In any case, thank you for helping me seeing it the clisp way. :-)

While it  may be hard to ask  for a full compatibility  with the emacs
command  line arguments,  (with  respect to  -x/--eval  etc), I  would
suggest to add "--" as alternate separator for the arguments passed to
ext:*arg* in addition to "".  Note that it is sometimes hard to ensure
the presence of an empty arguments.

---

From: Sam Steingold <[email-masked]>
Date: Tue Mar 18 09:35:21 2003

> * In message <[email-masked]>
> * On the subject of "Re: [clisp-list] arguments to a saved image?  3 suggestions."
> * Sent on Tue, 18 Mar 2003 06:12:50 +0100

you can have a file named "--" but not a file named "".

> You don't expect us to read the whole documentation, do you?

HUH?!

> the presence of an empty arguments.

try CVS head.
I added multiple -x and also -repl (enter REPL after -x &c)

$ ./clisp -x '(print (list ' -x ':args' -x ' *args*))' -q -norc -- 1 2 3 4 5 6 7

(:ARGS ("1" "2" "3" "4" "5" "6" "7")) 
(:ARGS ("1" "2" "3" "4" "5" "6" "7"))

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Stupidity, like virtue, is its own reward.

---

From: Christian Schuhegger <[email-masked]>
Date: Wed Mar 16 11:32:22 2005

Hello,

I created a saved image with an init function:
(ext:saveinitmem "pmm.mem" :quiet t :init-function 
#'production-memory-monitoring::init-function)

and I run it like proposed here:

> $ clisp -M image.mem "" my-arg1 my-arg2 my-arg3

actually like this:
/usr/bin/clisp -norc -M pmm.mem -- 
[email-masked]:~/stats-collecting/memory.txt 
[email-masked]:~/stats-collecting/memory.txt

Because the people that finally will use the program don't know Lisp I 
would like to have that they can exit the program in any case by 
pressing ctrl-c.

But I noticed that pressing ctrl-c leaves the program in the repl in the 
debugger.

from:
http://clisp.sourceforge.net/impnotes.html#script-exec
> Non-continuable errors and Control-C interrupts will terminate the execution of the Lisp script with an error status (using EXT:EXIT-ON-ERROR).
I see that under "script execution mode" a ctrl-c has this effect. Now 
my question is, how does clisp decide if it is in "script execution 
mode" or not? And can I perhaps set some flag that make clisp always 
exit on ctrl-c?

Many thanks for your infos,
-- 
Christian Schuhegger
http://www.el-chef.de

---

From: Sam Steingold <[email-masked]>
Date: Wed Mar 16 13:52:26 2005

> * Christian Schuhegger <[email-masked]> [2005-03-16 20:12:46 +0100]:
>
> Now my question is, how does clisp decide if it is in "script
> execution mode" or not?

if the file is given on the command line, i.e., if we load file and then
quit, this is script.
if we execute the driver (the :init-function), this is not a script.

> And can I perhaps set some flag that make
> clisp always exit on ctrl-c?

no.

why don't you just wrap your init-function in exit-on-error?

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.memri.org/> <http://www.openvotingconsortium.org/>
<http://www.honestreporting.com> <http://pmw.org.il/>
Any programming language is at its best before it is implemented and used.

---

From: Christian Schuhegger <[email-masked]>
Date: Wed Mar 16 22:43:12 2005

> if we execute the driver (the :init-function), this is not a script.

Thanks for the explanation.

> why don't you just wrap your init-function in exit-on-error?

Good point. I will do that. thanks.
-- 
Christian Schuhegger
http://www.el-chef.de