From: Pascal B. <pj...@in...> - 2003-03-17 07:53:56
|
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,=20 #!/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 na= me "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. =20 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. =20 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: =20 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]. --=20 __Pascal_Bourguignon__ http://www.informatimago.com/ ---------------------------------------------------------------------- Do not adjust your mind, there is a fault in reality. |